1 /*   sequin3.c
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *            National Center for Biotechnology Information (NCBI)
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government do not place any restriction on its use or reproduction.
13 *  We would, however, appreciate having the NCBI and the author cited in
14 *  any work or product based on this material
15 *
16 *  Although all reasonable efforts have been taken to ensure the accuracy
17 *  and reliability of the software and data, the NLM and the U.S.
18 *  Government do not and cannot warrant the performance or results that
19 *  may be obtained by using this software or data. The NLM and the U.S.
20 *  Government disclaim all warranties, express or implied, including
21 *  warranties of performance, merchantability or fitness for any particular
22 *  purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name:  sequin3.c
27 *
28 * Author:  Jonathan Kans
29 *
30 * Version Creation Date:   1/22/95
31 *
32 * $Revision: 6.1368 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date     Name        Description of modification
39 * -------  ----------  -----------------------------------------------------
40 *
41 *
42 * ==========================================================================
43 */
44 
45 #include "sequin.h"
46 #include <document.h>
47 #include <sequtil.h>
48 #include <biosrc.h>
49 #include <import.h>
50 #include <gather.h>
51 #include <asn2gnbk.h>
52 #include <asn2gnbp.h>
53 #include <edutil.h>
54 #include <gbfeat.h>
55 #include <gbftdef.h>
56 #include <subutil.h>    /* TOPOLOGY_xxx definitions */
57 #include <salutil.h>
58 #include <valid.h>
59 #include <vsm.h>
60 #include <bspview.h>
61 #include <toasn3.h>
62 #include <toporg.h>
63 #include <salstruc.h>
64 #include <explore.h>
65 #include <utilpub.h>
66 #include <tofasta.h>
67 #include <rpsutil.h>
68 #include <findrepl.h>
69 #include <explore.h>
70 #include <seqpanel.h>
71 #include <tax3api.h>
72 #include <saledit.h>
73 #include <alignmgr2.h>
74 #include <suggslp.h>
75 #include <asn2gnbi.h>
76 #include <alignval.h>
77 #include <cdrgn.h>
78 #include <salpanel.h>
79 #define NLM_GENERATED_CODE_PROTO
80 #include <objmacro.h>
81 #include <macrodlg.h>
82 #include <macroapi.h>
83 #include <valdlg.h>
84 #include <objvalid.h>
85 #include <valapi.h>
86 
87 /* For converting primer names to primer seqs and vice versa */
PrimerSeqToPrimerNameCallback(BioSourcePtr biop,Pointer userdata)88 static void PrimerSeqToPrimerNameCallback (BioSourcePtr biop, Pointer userdata)
89 {
90   PCRReactionSetPtr ps;
91   PCRPrimerPtr      pp;
92   CharPtr           tmp;
93 
94   if (biop == NULL || biop->pcr_primers == NULL) return;
95   for (ps = biop->pcr_primers; ps != NULL; ps = ps->next) {
96     for (pp = ps->forward; pp != NULL; pp = pp->next) {
97       tmp = pp->name;
98       pp->name = pp->seq;
99       pp->seq = tmp;
100     }
101     for (pp = ps->reverse; pp != NULL; pp = pp->next) {
102       tmp = pp->name;
103       pp->name = pp->seq;
104       pp->seq = tmp;
105     }
106   }
107 }
108 
109 
SwapPrimerNamesAndSeq(IteM i)110 static void SwapPrimerNamesAndSeq (IteM i)
111 {
112   BaseFormPtr  bfp;
113   SeqEntryPtr  sep;
114 
115 #ifdef WIN_MAC
116   bfp = currentFormDataPtr;
117 #else
118   bfp = GetObjectExtra (i);
119 #endif
120   if (bfp == NULL) return;
121   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
122   if (sep == NULL) return;
123   VisitBioSourcesInSep (sep, NULL, PrimerSeqToPrimerNameCallback);
124   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
125   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
126 }
127 
CreateTSAIDsFromLocalIDs(IteM i)128 static void CreateTSAIDsFromLocalIDs (IteM i)
129 {
130   BaseFormPtr  bfp;
131   SeqEntryPtr  sep;
132 
133 #ifdef WIN_MAC
134   bfp = currentFormDataPtr;
135 #else
136   bfp = GetObjectExtra (i);
137 #endif
138   if (bfp == NULL) return;
139   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
140   if (sep == NULL) return;
141 
142   ConvertLocalIdsToTSAIds (sep, NULL, NULL);
143 
144   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
145   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
146 }
147 
148 
149 typedef struct createtsaidswithsuffixform {
150   FORM_MESSAGE_BLOCK
151   TexT suffix;
152   DialoG text_portion;
153 } CreateTsaIDsWithSuffixFormData, PNTR CreateTsaIDsWithSuffixFormPtr;
154 
DoCreateTSAIDsFromLocalIDsWithSuffix(ButtoN b)155 static void DoCreateTSAIDsFromLocalIDsWithSuffix (ButtoN b)
156 {
157   CreateTsaIDsWithSuffixFormPtr t;
158   SeqEntryPtr                   sep;
159   CharPtr                       suffix = NULL;
160   TextPortionPtr                tp;
161 
162   t = (CreateTsaIDsWithSuffixFormPtr) GetObjectExtra (b);
163   if (b == NULL) {
164     return;
165   }
166 
167   sep = GetTopSeqEntryForEntityID (t->input_entityID);
168   if (sep == NULL) return;
169 
170   if (!TextHasNoText (t->suffix)) {
171     suffix = SaveStringFromText (t->suffix);
172   }
173   tp = DialogToPointer (t->text_portion);
174   ConvertLocalIdsToTSAIds (sep, suffix, tp);
175   suffix = MemFree (suffix);
176   tp = TextPortionFree (tp);
177 
178   ObjMgrSetDirtyFlag (t->input_entityID, TRUE);
179   ObjMgrSendMsg (OM_MSG_UPDATE, t->input_entityID, 0, 0);
180   Remove (t->form);
181   Update();
182 }
183 
CreateTSAIDsFromLocalIDsWithSuffix(IteM i)184 static void CreateTSAIDsFromLocalIDsWithSuffix (IteM i)
185 {
186   BaseFormPtr  bfp;
187   CreateTsaIDsWithSuffixFormPtr t;
188   WindoW       w;
189   GrouP        h, g, c;
190   ButtoN       b;
191 
192 #ifdef WIN_MAC
193   bfp = currentFormDataPtr;
194 #else
195   bfp = GetObjectExtra (i);
196 #endif
197   if (bfp == NULL) return;
198 
199   t = (CreateTsaIDsWithSuffixFormPtr) MemNew (sizeof (CreateTsaIDsWithSuffixFormData));
200 
201   w = FixedWindow (-50, -33, -10, -10, "Create TSA IDs With Suffix", StdCloseWindowProc);
202   h = HiddenGroup (w, -1, 0, NULL);
203   SetGroupSpacing (h, 10, 10);
204   t->form = (ForM) w;
205   t->input_entityID = bfp->input_entityID;
206 
207   g = HiddenGroup (h, 2, 0, NULL);
208   StaticPrompt (g, "Suffix", 0, dialogTextHeight, programFont, 'c');
209   t->suffix = DialogText (g, "", 14, NULL);
210 
211   t->text_portion = TextPortionDialog (h, TRUE, NULL, NULL);
212 
213   c = HiddenGroup (h, 2, 0, NULL);
214   b = DefaultButton (c, "Accept", DoCreateTSAIDsFromLocalIDsWithSuffix);
215   SetObjectExtra (b, t, NULL);
216   PushButton (c, "Cancel", StdCancelButtonProc);
217   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) t->text_portion, (HANDLE) c, NULL);
218 
219   Show (w);
220 
221 }
222 
223 
CreateTSAIDsFromTable(IteM i)224 static void CreateTSAIDsFromTable (IteM i)
225 {
226   BaseFormPtr  bfp;
227   SeqEntryPtr  sep;
228   Char         path [PATH_MAX];
229   FILE         *fp;
230   ValNodePtr   table, sequence_lists, err_list = NULL, vnp, vnp_rs, vnp_s, vnp_rt, vnp_t;
231   MatchTypeData match;
232   LogInfoPtr   lip;
233   BioseqPtr    bsp;
234   SeqIdPtr     sip_new;
235   DbtagPtr     dbtag;
236   CharPtr      db;
237 
238 #ifdef WIN_MAC
239   bfp = currentFormDataPtr;
240 #else
241   bfp = GetObjectExtra (i);
242 #endif
243   if (bfp == NULL) return;
244   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
245   if (sep == NULL) return;
246 
247   if (! GetInputFileName (path, sizeof (path), "", "TEXT")) return;
248   fp = FileOpen (path, "r");
249   if (fp == NULL) return;
250   table = ReadTabTableFromFile (fp);
251   FileClose (fp);
252 
253   match.choice = eTableMatchNucID;
254   match.data = NULL;
255   match.match_location = String_location_equals;
256 
257   sequence_lists = GetSequenceListsForMatchTypeInTabTable (sep, table, 0, &match, &err_list);
258 
259   if (err_list != NULL) {
260     lip = OpenLog ("Table Problems");
261     for (vnp = err_list; vnp != NULL; vnp = vnp->next) {
262       fprintf (lip->fp, "%s\n", (CharPtr) vnp->data.ptrvalue);
263     }
264     lip->data_in_log = TRUE;
265     CloseLog (lip);
266     lip = FreeLog (lip);
267     err_list = ValNodeFreeData (err_list);
268     if (ANS_YES != Message (MSG_YN, "Continue with table problems")) {
269       sequence_lists = FreeSequenceLists(sequence_lists);
270       table = FreeTabTable (table);
271       return;
272     }
273   }
274 
275   WatchCursor();
276   Update();
277   for (vnp_rs = sequence_lists, vnp_rt = table;
278        vnp_rs != NULL && vnp_rt != NULL;
279        vnp_rs = vnp_rs->next, vnp_rt = vnp_rt->next) {
280     vnp_s = vnp_rs->data.ptrvalue;
281     vnp_t = vnp_rt->data.ptrvalue;
282     if (vnp_s == NULL || vnp_t == NULL) {
283       continue;
284     }
285     vnp_t = vnp_t->next;
286     if (vnp_t == NULL || StringHasNoText (vnp_t->data.ptrvalue)) {
287       continue;
288     }
289     while (vnp_s != NULL) {
290       bsp = (BioseqPtr) vnp_s->data.ptrvalue;
291       db = GetTSAIDDB(bsp);
292       if (db != NULL) {
293         dbtag = DbtagNew ();
294         dbtag->db = db;
295         dbtag->tag = ObjectIdNew ();
296         dbtag->tag->str = StringSave (vnp_t->data.ptrvalue);
297         sip_new = ValNodeNew (NULL);
298         sip_new->choice = SEQID_GENERAL;
299         sip_new->data.ptrvalue = dbtag;
300         sip_new->next = bsp->id;
301         bsp->id = sip_new;
302         SeqMgrReplaceInBioseqIndex (bsp);
303       }
304       vnp_s = vnp_s->next;
305     }
306   }
307   sequence_lists = FreeSequenceLists(sequence_lists);
308   table = FreeTabTable (table);
309   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
310   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
311   ArrowCursor();
312   Update();
313 
314 }
315 
316 
317 
318 
DoCreateTSAIDsFromDefline(ButtoN b)319 static void DoCreateTSAIDsFromDefline (ButtoN b)
320 {
321   CreateTsaIDsWithSuffixFormPtr t;
322   SeqEntryPtr                   sep;
323   CharPtr                       suffix = NULL;
324   TextPortionPtr                text_portion = NULL;
325 
326   t = (CreateTsaIDsWithSuffixFormPtr) GetObjectExtra (b);
327   if (b == NULL) {
328     return;
329   }
330 
331   sep = GetTopSeqEntryForEntityID (t->input_entityID);
332   if (sep == NULL) return;
333 
334   if (!TextHasNoText (t->suffix)) {
335     suffix = SaveStringFromText (t->suffix);
336   }
337   text_portion = DialogToPointer (t->text_portion);
338   CreateTSAIDsFromDeflineInSep (sep, suffix, text_portion);
339 
340   suffix = MemFree (suffix);
341   text_portion = TextPortionFree (text_portion);
342 
343   ObjMgrSetDirtyFlag (t->input_entityID, TRUE);
344   ObjMgrSendMsg (OM_MSG_UPDATE, t->input_entityID, 0, 0);
345   Remove (t->form);
346   Update();
347 }
348 
349 
CreateTSAIDsFromDefline(IteM i)350 static void CreateTSAIDsFromDefline (IteM i)
351 {
352   BaseFormPtr  bfp;
353   CreateTsaIDsWithSuffixFormPtr t;
354   WindoW       w;
355   GrouP        h, g, c;
356   ButtoN       b;
357 
358 #ifdef WIN_MAC
359   bfp = currentFormDataPtr;
360 #else
361   bfp = GetObjectExtra (i);
362 #endif
363   if (bfp == NULL) return;
364 
365   t = (CreateTsaIDsWithSuffixFormPtr) MemNew (sizeof (CreateTsaIDsWithSuffixFormData));
366 
367   w = FixedWindow (-50, -33, -10, -10, "Create TSA IDs from Defline", StdCloseWindowProc);
368   h = HiddenGroup (w, -1, 0, NULL);
369   SetGroupSpacing (h, 10, 10);
370   t->form = (ForM) w;
371   t->input_entityID = bfp->input_entityID;
372 
373   t->text_portion = TextPortionDialog (h, TRUE, NULL, NULL);
374 
375   g = HiddenGroup (h, 2, 0, NULL);
376   StaticPrompt (g, "Suffix", 0, dialogTextHeight, programFont, 'c');
377   t->suffix = DialogText (g, "", 14, NULL);
378 
379   c = HiddenGroup (h, 2, 0, NULL);
380   b = DefaultButton (c, "Accept", DoCreateTSAIDsFromDefline);
381   SetObjectExtra (b, t, NULL);
382   PushButton (c, "Cancel", StdCancelButtonProc);
383   AlignObjects (ALIGN_CENTER, (HANDLE) t->text_portion, (HANDLE) g, (HANDLE) c, NULL);
384 
385   Show (w);
386 
387 }
388 
389 
CreateBarcodeIDsFromLocalIDs(IteM i)390 static void CreateBarcodeIDsFromLocalIDs (IteM i)
391 {
392   BaseFormPtr  bfp;
393   SeqEntryPtr  sep;
394 
395 #ifdef WIN_MAC
396   bfp = currentFormDataPtr;
397 #else
398   bfp = GetObjectExtra (i);
399 #endif
400   if (bfp == NULL) return;
401   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
402   if (sep == NULL) return;
403 
404   ConvertLocalIdsToBarcodeIds (sep);
405 
406   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
407   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
408 }
409 
410 
411 #define DDBUFFERMAX 32768
412 
413 typedef struct fndeldata {
414   CharPtr     buffer;
415   CharPtr     curr;
416   Int4        seqlen;
417   Int4        gap_count;
418   Int4        bsp_length;
419   Boolean     in_gap;
420   Boolean     unk_gap;
421   ValNodePtr  head;
422   ValNodePtr  last;
423 } DelData, PNTR DelDataPtr;
424 
AddNextBlock(DelDataPtr ddp)425 static void AddNextBlock (
426   DelDataPtr ddp
427 )
428 
429 {
430   ByteStorePtr  bs;
431   IntFuzzPtr    ifp;
432   SeqLitPtr     slitp;
433   CharPtr       str;
434   ValNodePtr    vnp;
435 
436   if (ddp == NULL) return;
437   if (ddp->in_gap) {
438     slitp = (SeqLitPtr) MemNew (sizeof (SeqLit));
439     if (slitp != NULL) {
440       slitp->length = ddp->gap_count;
441       ddp->bsp_length += slitp->length;
442       if (ddp->unk_gap) {
443         ifp = IntFuzzNew ();
444         if (ifp != NULL) {
445           ifp->choice = 4;
446           slitp->fuzz = ifp;
447         }
448       }
449       vnp = ValNodeAddPointer (&(ddp->last), 2, (Pointer) slitp);
450       if (ddp->head == NULL) {
451         ddp->head = vnp;
452       }
453       ddp->last = vnp;
454     }
455   } else if (ddp->seqlen > 0) {
456     str = ddp->curr;
457     if (str != NULL) {
458       *str = '\0';
459     }
460     bs = BSNew (ddp->seqlen);
461     if (bs != NULL) {
462       BSWrite (bs, (VoidPtr) ddp->buffer, ddp->seqlen);
463       slitp = (SeqLitPtr) MemNew (sizeof (SeqLit));
464       if (slitp != NULL) {
465         slitp->length = ddp->seqlen;
466         slitp->seq_data_type = Seq_code_iupacna;
467         slitp->seq_data = (SeqDataPtr) bs;
468         ddp->bsp_length += slitp->length;
469         vnp = ValNodeAddPointer (&(ddp->last), 2, (Pointer) slitp);
470         if (ddp->head == NULL) {
471           ddp->head = vnp;
472         }
473         ddp->last = vnp;
474       }
475     }
476   }
477 }
478 
FarToNearCallback(CharPtr sequence,Pointer userdata)479 static void LIBCALLBACK FarToNearCallback (
480   CharPtr sequence,
481   Pointer userdata
482 )
483 
484 {
485   Char        ch;
486   DelDataPtr  ddp;
487   CharPtr     ptr;
488   CharPtr     str;
489 
490   if (sequence == NULL || userdata == NULL) return;
491   ddp = (DelDataPtr) userdata;
492 
493   ptr = sequence;
494   ch = *ptr;
495   str = ddp->curr;
496 
497   while (ch != '\0') {
498     if (ch != '-' && ch != '+') {
499       if (ddp->in_gap) {
500         AddNextBlock (ddp);
501         ddp->in_gap = FALSE;
502         ddp->unk_gap = FALSE;
503         ddp->gap_count = 0;
504         ddp->curr = ddp->buffer;
505         ddp->seqlen = 0;
506         str = ddp->curr;
507       }
508       *str = ch;
509       str++;
510       (ddp->seqlen)++;
511       if (ddp->seqlen >= DDBUFFERMAX) {
512         *str = '\0';
513         ddp->curr = str;
514         AddNextBlock (ddp);
515         ddp->curr = ddp->buffer;
516         ddp->seqlen = 0;
517         str = ddp->curr;
518       }
519     } else {
520       if (! ddp->in_gap) {
521         AddNextBlock (ddp);
522         ddp->in_gap = TRUE;
523         ddp->unk_gap = (Boolean) (ch == '-');
524         ddp->gap_count = 0;
525         ddp->curr = ddp->buffer;
526         ddp->seqlen = 0;
527         str = ddp->curr;
528       }
529       (ddp->gap_count)++;
530     }
531 
532     ptr++;
533     ch = *ptr;
534   }
535   ddp->curr = str;
536 }
537 
FarToNearProc(BioseqPtr bsp,Pointer userdata)538 static void FarToNearProc (BioseqPtr bsp, Pointer userdata)
539 
540 {
541   DelData  dd;
542   Pointer  olddelta;
543 
544   if (bsp == NULL || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4) return;
545   MemSet ((Pointer) &dd, 0, sizeof (DelData));
546   dd.buffer = MemNew (sizeof (Char) * (DDBUFFERMAX + 2));
547   if (dd.buffer == NULL) return;
548   dd.curr = dd.buffer;
549   dd.seqlen = 0;
550   SeqPortStream (bsp, EXPAND_GAPS_TO_DASHES | KNOWN_GAP_AS_PLUS, (Pointer) &dd, FarToNearCallback);
551   AddNextBlock (&dd);
552   MemFree (dd.buffer);
553   olddelta = bsp->seq_ext;
554   bsp->seq_ext = (Pointer) dd.head;
555   if (dd.bsp_length != bsp->length) {
556     Message (MSG_OK, "Old length %ld differs from new length %ld",
557              (long) bsp->length, (long) dd.bsp_length);
558   }
559 }
560 
FarDeltaToNear(IteM i)561 static void FarDeltaToNear (IteM i)
562 
563 {
564   BaseFormPtr  bfp;
565   SeqEntryPtr  sep;
566 
567 #ifdef WIN_MAC
568   bfp = currentFormDataPtr;
569 #else
570   bfp = GetObjectExtra (i);
571 #endif
572   if (bfp == NULL) return;
573   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
574   if (sep == NULL) return;
575   VisitBioseqsInSep (sep, NULL, FarToNearProc);
576   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
577   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
578   Message (MSG_OK, "Some manual desktop manipulations remain");
579 }
580 
581 static CharPtr HIVStarts[] = {
582  "##HIVDataBaseData-START##",
583  "##HIV-1DataBaseData-START##",
584  "##HIVData-START##",
585  NULL};
586 
587 static CharPtr HIVEnds[] = {
588  "##HIVDataBaseData-END##",
589  "##HIV-1DataBaseData-END##",
590  "##HIVData-END##",
591  NULL};
592 
593 
594 static CharPtr FluStart = "##FluData-START##";
595 static CharPtr FluEnd = "##FluData-END##";
596 
597 
RemoveStructuredCommentFromString(CharPtr str,CharPtr prefix,CharPtr suffix)598 static void RemoveStructuredCommentFromString (CharPtr str, CharPtr prefix, CharPtr suffix)
599 {
600   CharPtr pPrefix, pSuffix, pAfter;
601 
602   if (StringHasNoText (str) || StringHasNoText (prefix) || StringHasNoText (suffix)) return;
603 
604   pPrefix = StringSearch (str, prefix);
605   pSuffix = StringSearch (str, suffix);
606   if (pPrefix == NULL || pSuffix == NULL || pPrefix >= pSuffix) return;
607 
608   pAfter = pSuffix + StringLen (suffix);
609   StringCpy (pPrefix, pAfter);
610 }
611 
612 
FindStructComment(SeqDescrPtr sdp,Pointer userdata)613 static void FindStructComment (SeqDescrPtr sdp, Pointer userdata)
614 
615 {
616   CharPtr        str;
617   UserObjectPtr  uop = NULL;
618   UserObjectPtr  PNTR uopp;
619   CharPtr        prefix = "", suffix = "";
620   Int4           i;
621 
622   if (sdp == NULL || sdp->choice != Seq_descr_comment) return;
623   str = (CharPtr) sdp->data.ptrvalue;
624   if (StringHasNoText (str)) return;
625   uopp = (UserObjectPtr PNTR) userdata;
626   if (uopp == NULL) return;
627 
628   for (i = 0; HIVStarts[i] != NULL; i++) {
629     if (StringStr (str, HIVStarts[i]) != NULL) {
630       prefix = HIVStarts[i];
631       suffix = HIVEnds[i];
632       break;
633     }
634   }
635   if (StringHasNoText (prefix) && StringStr (str, FluStart) != NULL) {
636     prefix = FluStart;
637     prefix = FluEnd;
638   }
639 
640   uop = ParseStringIntoStructuredComment (NULL, str, prefix, suffix);
641 
642   if (uop != NULL) {
643     *uopp = uop;
644     RemoveStructuredCommentFromString (str, prefix, suffix);
645     if (StringHasNoText (str) && sdp->extended != 0) {
646       ((ObjValNodePtr)sdp)->idx.deleteme = TRUE;
647     }
648   }
649 }
650 
DoStructCommentBsp(BioseqPtr bsp,Pointer userdata)651 static void DoStructCommentBsp (BioseqPtr bsp, Pointer userdata)
652 
653 {
654   SeqDescrPtr    sdp;
655   UserObjectPtr  uop = NULL;
656 
657   VisitDescriptorsOnBsp (bsp, (Pointer) &uop, FindStructComment);
658   if (uop == NULL) return;
659   sdp = CreateNewDescriptorOnBioseq (bsp, Seq_descr_user);
660   if (sdp == NULL) return;
661   sdp->data.ptrvalue = uop;
662 }
663 
ParseCommentIntoStructuredObject(IteM i)664 static void ParseCommentIntoStructuredObject (IteM i)
665 
666 {
667   BaseFormPtr  bfp;
668   SeqEntryPtr  sep;
669 
670 #ifdef WIN_MAC
671   bfp = currentFormDataPtr;
672 #else
673   bfp = GetObjectExtra (i);
674 #endif
675   if (bfp == NULL) return;
676   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
677   if (sep == NULL) return;
678 
679   VisitBioseqsInSep (sep, NULL, DoStructCommentBsp);
680 
681   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
682   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
683   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
684   Update ();
685 }
686 
DoStructuredTag(SeqDescrPtr sdp,Pointer userdata)687 static void DoStructuredTag (SeqDescrPtr sdp, Pointer userdata)
688 
689 {
690   if (sdp->choice == Seq_descr_user) {
691     AddDatabaseNameToStructuredComment ((UserObjectPtr) sdp->data.ptrvalue, (CharPtr)userdata);
692   }
693 }
694 
AddStructuredCommentTag(IteM i,CharPtr dbname)695 static void AddStructuredCommentTag (IteM i, CharPtr dbname)
696 
697 {
698   BaseFormPtr  bfp;
699   SeqEntryPtr  sep;
700 
701 #ifdef WIN_MAC
702   bfp = currentFormDataPtr;
703 #else
704   bfp = GetObjectExtra (i);
705 #endif
706   if (bfp == NULL) return;
707   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
708   if (sep == NULL) return;
709 
710   VisitDescriptorsInSep (sep, dbname, DoStructuredTag);
711 
712   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
713   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
714   Update ();
715 }
716 
AddStructuredCommentHivTag(IteM i)717 static void AddStructuredCommentHivTag (IteM i)
718 {
719   AddStructuredCommentTag (i, "HIV");
720 }
721 
722 
AddStructuredCommentFluTag(IteM i)723 static void AddStructuredCommentFluTag (IteM i)
724 
725 {
726   AddStructuredCommentTag (i, "Flu");
727 }
728 
729 
AddStructuredCommentMIGSTag(IteM i)730 static void AddStructuredCommentMIGSTag (IteM i)
731 
732 {
733   AddStructuredCommentTag (i, "MIGS");
734 }
735 
736 
AddStructuredCommentMIMSTag(IteM i)737 static void AddStructuredCommentMIMSTag (IteM i)
738 
739 {
740   AddStructuredCommentTag (i, "MIMS");
741 }
742 
743 
AddStructuredCommentMIENSTag(IteM i)744 static void AddStructuredCommentMIENSTag (IteM i)
745 
746 {
747   AddStructuredCommentTag (i, "MIENS");
748 }
749 
750 
AddStructuredCommentMIMARKS30Tag(IteM i)751 static void AddStructuredCommentMIMARKS30Tag (IteM i)
752 
753 {
754   AddStructuredCommentTag (i, "MIMARKS:3.0");
755 }
756 
757 
AddStructuredCommentMIGS30Tag(IteM i)758 static void AddStructuredCommentMIGS30Tag (IteM i)
759 
760 {
761   AddStructuredCommentTag (i, "MIGS:3.0");
762 }
763 
764 
AddStructuredCommentMIMS30Tag(IteM i)765 static void AddStructuredCommentMIMS30Tag (IteM i)
766 
767 {
768   AddStructuredCommentTag (i, "MIMS:3.0");
769 }
770 
771 
AddStructuredCommentAssemblyDataTag(IteM i)772 static void AddStructuredCommentAssemblyDataTag (IteM i)
773 
774 {
775   AddStructuredCommentTag (i, "Assembly");
776 }
777 
778 
AddStructuredCommentGenomeAssemblyDataTag(IteM i)779 static void AddStructuredCommentGenomeAssemblyDataTag (IteM i)
780 
781 {
782   AddStructuredCommentTag (i, "Genome-Assembly");
783 }
784 
785 
AddStructuredCommentiBOLTag(IteM i)786 static void AddStructuredCommentiBOLTag (IteM i)
787 
788 {
789   AddStructuredCommentTag (i, "International Barcode of Life (iBOL)Data");
790 }
791 
792 
DoReorderStructuredCommentFields(SeqDescrPtr sdp,Pointer userdata)793 static void DoReorderStructuredCommentFields (SeqDescrPtr sdp, Pointer userdata)
794 
795 {
796   if (sdp->choice == Seq_descr_user) {
797     ReorderStructuredCommentFields ((UserObjectPtr) sdp->data.ptrvalue);
798   }
799 }
800 
ReorderStructuredCommentFieldsItem(IteM i)801 static void ReorderStructuredCommentFieldsItem (IteM i)
802 
803 {
804   BaseFormPtr  bfp;
805   SeqEntryPtr  sep;
806 
807 #ifdef WIN_MAC
808   bfp = currentFormDataPtr;
809 #else
810   bfp = GetObjectExtra (i);
811 #endif
812   if (bfp == NULL) return;
813   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
814   if (sep == NULL) return;
815 
816   VisitDescriptorsInSep (sep, NULL, DoReorderStructuredCommentFields);
817 
818   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
819   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
820   Update ();
821 }
822 
823 
ExportStructuredCommentTable(IteM i)824 static void ExportStructuredCommentTable (IteM i)
825 
826 {
827   BaseFormPtr  bfp;
828   SeqEntryPtr  sep;
829   ValNodePtr   table;
830   Char         path [PATH_MAX];
831   FILE         *fp;
832 
833 #ifdef WIN_MAC
834   bfp = currentFormDataPtr;
835 #else
836   bfp = GetObjectExtra (i);
837 #endif
838   if (bfp == NULL) return;
839 
840   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
841 
842   table = CreateStructuredCommentTableFromSeqEntry (sep);
843 
844   if (table == NULL) {
845     Message (MSG_ERROR, "No structured comments found!");
846     return;
847   }
848 
849   path [0] = '\0';
850   if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), NULL)) {
851     fp = FileOpen (path, "w");
852     if (!fp) {
853       Message (MSG_ERROR, "Unable to open %s", path);
854     } else {
855       WriteTabTableToFile (table, fp);
856       FileClose (fp);
857     }
858   }
859   table = FreeTabTable(table);
860 
861 }
862 
863 
ConvertBadInfProc(SeqFeatPtr sfp,Pointer userdata)864 static void ConvertBadInfProc (SeqFeatPtr sfp, Pointer userdata)
865 
866 {
867   GBQualPtr  gbq;
868   size_t     len;
869   CharPtr    ptr, str;
870 
871   if (sfp == NULL) return;
872   for (gbq = sfp->qual; gbq != NULL; gbq = gbq->next) {
873     if (StringICmp (gbq->qual, "inference") != 0) continue;
874     if (ValidateInferenceQualifier (gbq->val, FALSE) != VALID_INFERENCE) {
875       if (StringNICmp (gbq->val, "similar to ", 11) == 0) {
876         ptr = StringChr (gbq->val, ':');
877         if (ptr != NULL) {
878           ptr++;
879           if (StringDoesHaveText (ptr)) {
880             len = StringLen ("similar to ") + StringLen (ptr);
881             str = MemNew (len + 5);
882             if (str != NULL) {
883               StringCpy (str, "similar to ");
884               StringCat (str, ptr);
885               gbq->val = MemFree (gbq->val);
886               gbq->val = StringSave (str);
887               MemFree (str);
888             }
889           }
890         }
891       }
892       gbq->qual = MemFree (gbq->qual);
893       gbq->qual = StringSave ("note");
894     }
895   }
896 }
897 
ConvertBadInferenceToNote(IteM i)898 static void ConvertBadInferenceToNote (IteM i)
899 
900 {
901   BaseFormPtr  bfp;
902   SeqEntryPtr  sep;
903 
904 #ifdef WIN_MAC
905   bfp = currentFormDataPtr;
906 #else
907   bfp = GetObjectExtra (i);
908 #endif
909   if (bfp == NULL) return;
910 
911   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
912 
913   VisitFeaturesInSep (sep, NULL, ConvertBadInfProc);
914 
915   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
916   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
917   Update ();
918 }
919 
920 typedef struct {
921   Boolean dirtyFlag;
922   Int2    number;
923 } CdsDelStruct, PNTR CdsDelStructPtr;
924 
925 typedef struct {
926   FORM_MESSAGE_BLOCK
927   Int2  number;
928 } CdsDelForm, PNTR CdsDelFormPtr;
929 
AddOrgNameToDefLines(IteM i)930 static void AddOrgNameToDefLines (IteM i)
931 
932 {
933   CommonAddOrgOrModsToDefLines (i, 0, 0, NULL);
934 }
935 
AddStrainToDefLines(IteM i)936 static void AddStrainToDefLines (IteM i)
937 
938 {
939   CommonAddOrgOrModsToDefLines (i, ORGMOD_strain, 0, NULL);
940 }
941 
AddCloneToDefLines(IteM i)942 static void AddCloneToDefLines (IteM i)
943 
944 {
945   CommonAddOrgOrModsToDefLines (i, 0, SUBSRC_clone, NULL);
946 }
947 
AddIsolateToDefLines(IteM i)948 static void AddIsolateToDefLines (IteM i)
949 
950 {
951   CommonAddOrgOrModsToDefLines (i, ORGMOD_isolate, 0, NULL);
952 }
953 
AddHaplotypeToDefLines(IteM i)954 static void AddHaplotypeToDefLines (IteM i)
955 
956 {
957   CommonAddOrgOrModsToDefLines (i, 0, SUBSRC_haplotype, NULL);
958 }
959 
AddCultivarToDefLines(IteM i)960 static void AddCultivarToDefLines (IteM i)
961 
962 {
963   CommonAddOrgOrModsToDefLines (i, ORGMOD_cultivar, 0, NULL);
964 }
965 
966 CharPtr kIndexerUpdateVecScreenText = "Sequence update by database staff to remove vector contamination";
967 
AddCitSubForUpdateProc(BaseFormPtr bfp)968 static void AddCitSubForUpdateProc (BaseFormPtr bfp)
969 
970 {
971   SeqEntryPtr  sep;
972   ValNodePtr   msg_list;
973   Boolean      successful = FALSE;
974 
975   if (bfp == NULL) return;
976   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
977   if (sep == NULL) return;
978 
979   msg_list = CreateUpdateCitSubFromBestTemplate (sep, sep, kSubmitterUpdateText);
980   if (msg_list != NULL) {
981     if (msg_list->choice == 0) {
982       Message (MSG_ERROR, (CharPtr) msg_list->data.ptrvalue);
983     } else {
984       Message (MSG_OK, (CharPtr) msg_list->data.ptrvalue);
985       successful = TRUE;
986     }
987     msg_list = ValNodeFree (msg_list);
988   }
989 
990   if (successful)
991   {
992     ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
993     ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
994     Update ();
995   }
996   return;
997 }
998 
AddCitSubForUpdate(IteM i)999 static void AddCitSubForUpdate (IteM i)
1000 
1001 {
1002   BaseFormPtr  bfp;
1003 
1004 #ifdef WIN_MAC
1005   bfp = currentFormDataPtr;
1006 #else
1007   bfp = GetObjectExtra (i);
1008 #endif
1009   AddCitSubForUpdateProc (bfp);
1010 }
1011 
1012 /* FixLocus is copied from taxutil, then modified to remove embl_code use */
FixLocus(SeqEntryPtr sep,Pointer data,Int4 index,Int2 indent)1013 static void FixLocus (SeqEntryPtr sep, Pointer data, Int4 index, Int2 indent)
1014 {
1015 	BioseqPtr bsp;
1016 	ValNodePtr vnp;
1017     TextSeqIdPtr tsip;
1018     Char tbuf[40];
1019 	CharPtr ptr, embl_code;
1020 
1021 	if (! IS_Bioseq(sep))
1022 		return;
1023 
1024 	bsp = (BioseqPtr)(sep->data.ptrvalue);
1025     embl_code = (CharPtr) data;
1026 	/* if (! embl_code) return; */
1027 
1028     for (vnp = bsp->id; vnp != NULL; vnp = vnp->next) {
1029 		if ((vnp->choice == SEQID_GENBANK || vnp->choice == SEQID_TPG) && vnp->data.ptrvalue != NULL) {
1030 			tsip = (TextSeqIdPtr) (vnp->data.ptrvalue);
1031 			if (tsip->accession != NULL)
1032 			{
1033 				tsip->name = MemFree (tsip->name);
1034 				if (bsp->repr != Seq_repr_seg) {
1035 					/* ptr = StringMove (tbuf, embl_code); */
1036 					ptr = tbuf;
1037 					StringMove (ptr, tsip->accession);
1038 					tsip->name = StringSave (tbuf);
1039 					SeqMgrReplaceInBioseqIndex (bsp);
1040 				}
1041 				return;
1042 			}
1043 		}
1044 	}
1045 
1046 	return;
1047 }
1048 
1049 extern void DoFixupLocus (SeqEntryPtr sep);
DoFixupLocus(SeqEntryPtr sep)1050 extern void DoFixupLocus (SeqEntryPtr sep)
1051 
1052 {
1053   BioSourcePtr  biop;
1054   BioseqSetPtr  bssp;
1055   CharPtr       embl_code;
1056   OrgRefPtr     orp;
1057   ValNodePtr    sdp;
1058 
1059   if (IS_Bioseq_set (sep)) {
1060     bssp = (BioseqSetPtr) sep->data.ptrvalue;
1061     if (bssp != NULL && (bssp->_class == 7 ||
1062                          (IsPopPhyEtcSet (bssp->_class)))) {
1063       for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
1064         DoFixupLocus (sep);
1065       }
1066       return;
1067     }
1068   }
1069   sdp = SeqEntryGetSeqDescr (sep, Seq_descr_source, NULL);
1070   if (sdp == NULL) return;
1071   biop = (BioSourcePtr) sdp->data.ptrvalue;
1072   if (biop == NULL) return;
1073   orp = biop->org;
1074   if (orp == NULL) return;
1075   /* embl_code = get_embl_code (orp); */
1076   embl_code = NULL;
1077   SeqEntryExplore (sep, (Pointer) embl_code, FixLocus);
1078   MemFree (embl_code);
1079 }
1080 
GetTSIPforBSP(BioseqPtr bsp)1081 static TextSeqIdPtr GetTSIPforBSP (BioseqPtr bsp)
1082 
1083 {
1084   SeqIdPtr      sip;
1085   TextSeqIdPtr  tsip = NULL;
1086 
1087   if (bsp == NULL) return NULL;
1088 
1089   for (sip = bsp->id; sip != NULL; sip = sip->next) {
1090     if (sip->choice == SEQID_GENBANK || sip->choice == SEQID_TPG) {
1091       tsip = (TextSeqIdPtr) sip->data.ptrvalue;
1092     }
1093   }
1094 
1095   return tsip;
1096 }
1097 
DoFixPartLocus(SeqEntryPtr sep,CharPtr prefix,Int2 segment,Int2 digits)1098 static void DoFixPartLocus (SeqEntryPtr sep, CharPtr prefix, Int2 segment, Int2 digits)
1099 
1100 {
1101   BioseqPtr     bsp;
1102   Char          ch;
1103   Char          digs [16];
1104   CharPtr       ptr;
1105   Char          str [32];
1106   TextSeqIdPtr  tsip;
1107 
1108   if (sep == NULL || prefix == NULL) return;
1109   if (! IS_Bioseq (sep)) return;
1110   bsp = (BioseqPtr) sep->data.ptrvalue;
1111   if (bsp == NULL) return;
1112   if (bsp->repr != Seq_repr_raw && bsp->repr != Seq_repr_const) return;
1113   tsip = GetTSIPforBSP (bsp);
1114   if (tsip == NULL) return;
1115   tsip->name = MemFree (tsip->name);
1116   sprintf (digs, "%*d", (int) digits, (int) segment);
1117   ptr = digs;
1118   ch = *ptr;
1119   while (ch != '\0') {
1120     if (ch == ' ') {
1121       *ptr = '0';
1122     }
1123     ptr++;
1124     ch = *ptr;
1125   }
1126   sprintf (str, "%sS%s", prefix, digs);
1127   tsip->name = StringSave (str);
1128 }
1129 
1130 extern void DoFixupSegSet (SeqEntryPtr sep);
DoFixupSegSet(SeqEntryPtr sep)1131 extern void DoFixupSegSet (SeqEntryPtr sep)
1132 
1133 {
1134   CharPtr       accn;
1135   Uint1         chs;
1136   Int2          digits;
1137   BioseqPtr     nbsp;
1138   BioseqSetPtr  bssp;
1139   size_t        len;
1140   SeqEntryPtr   nsep;
1141   Int2          numsegs;
1142   BioseqSetPtr  pbssp;
1143   CharPtr       prefix;
1144   SeqEntryPtr   psep;
1145   BioseqPtr     sbsp;
1146   Int2          segment;
1147   SeqIdPtr      sip;
1148   Char          str [32];
1149   Char          tmp [128];
1150   TextSeqIdPtr  tsip;
1151 
1152   if (! IS_Bioseq_set (sep)) return;
1153   bssp = (BioseqSetPtr) sep->data.ptrvalue;
1154   if (bssp == NULL) return;
1155   if (bssp->_class != BioseqseqSet_class_segset) {
1156     for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
1157       DoFixupSegSet (sep);
1158     }
1159     return;
1160   }
1161   nsep = FindNucSeqEntry (sep);
1162   if (nsep == NULL) return;
1163   if (! IS_Bioseq (nsep)) return;
1164   nbsp = (BioseqPtr) nsep->data.ptrvalue;
1165   if (nbsp == NULL) return;
1166   if (nbsp->repr != Seq_repr_seg) return;
1167   sbsp = NULL;
1168   tsip = GetTSIPforBSP (nbsp);
1169   if (tsip == NULL || StringHasNoText (tsip->accession)) {
1170     sbsp = nbsp;
1171     nsep = FindNthSeqEntry (sep, 4);
1172     if (nsep == NULL) return;
1173     if (! IS_Bioseq (nsep)) return;
1174     nbsp = (BioseqPtr) nsep->data.ptrvalue;
1175     if (nbsp == NULL) return;
1176     if (nbsp->repr != Seq_repr_raw && nbsp->repr != Seq_repr_const) return;
1177     tsip = GetTSIPforBSP (nbsp);
1178   }
1179   if (tsip == NULL) return;
1180   chs = SEQID_GENBANK;
1181   for (sip = nbsp->id; sip != NULL; sip = sip->next) {
1182     if (sip->choice == SEQID_GENBANK || sip->choice == SEQID_TPG) {
1183       chs = sip->choice;
1184     }
1185   }
1186   accn = tsip->accession;
1187   if (StringHasNoText (accn)) return;
1188   psep = FindBioseqSetByClass (sep, BioseqseqSet_class_parts);
1189   if (psep == NULL) return;
1190   pbssp = (BioseqSetPtr) psep->data.ptrvalue;
1191   if (pbssp == NULL) return;
1192   for (sep = pbssp->seq_set, numsegs = 0; sep != NULL; sep = sep->next, numsegs++) continue;
1193   StringNCpy_0 (tmp, accn, sizeof (tmp));
1194   prefix = tmp;
1195   len = StringLen (prefix);
1196   if (numsegs > 999) {
1197     digits = 4;
1198   } else if (numsegs > 99) {
1199     digits = 3;
1200   } else if (numsegs > 9) {
1201     digits = 2;
1202   } else {
1203     digits = 1;
1204   }
1205   if (digits + 1 + len > 16) {
1206     prefix += digits + 1 + len - 16;
1207   }
1208 
1209   for (sep = pbssp->seq_set, segment = 1; sep != NULL; sep = sep->next, segment++) {
1210     DoFixPartLocus (sep, prefix, segment, digits);
1211   }
1212 
1213   if (sbsp == NULL) return;
1214   tsip = NULL;
1215   for (sip = sbsp->id; sip != NULL; sip = sip->next) {
1216     if (sip->choice == SEQID_GENBANK || sip->choice == SEQID_TPG) {
1217       tsip = (TextSeqIdPtr) sip->data.ptrvalue;
1218     }
1219   }
1220   if (tsip == NULL) {
1221     tsip = TextSeqIdNew ();
1222     if (tsip == NULL) return;
1223     ValNodeAddPointer (&(sbsp->id), chs, (Pointer) tsip);
1224   }
1225   tsip->name = MemFree (tsip->name);
1226   sprintf (str, "SEG_%sS", prefix);
1227   tsip->name = StringSave (str);
1228   SeqMgrReplaceInBioseqIndex (sbsp);
1229 }
1230 
ForceLocusFixup(IteM i)1231 static void ForceLocusFixup (IteM i)
1232 
1233 {
1234   BaseFormPtr  bfp;
1235   SeqEntryPtr  sep;
1236   ErrSev       sev;
1237 
1238 #ifdef WIN_MAC
1239   bfp = currentFormDataPtr;
1240 #else
1241   bfp = GetObjectExtra (i);
1242 #endif
1243   if (bfp == NULL) return;
1244   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1245   if (sep == NULL) return;
1246   sev = ErrSetMessageLevel (SEV_FATAL);
1247   WatchCursor ();
1248   Update ();
1249   DoFixupLocus (sep);
1250   DoFixupSegSet (sep);
1251   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1252   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1253   ArrowCursor ();
1254   Update ();
1255   ErrSetMessageLevel (sev);
1256   ErrClear ();
1257   ErrShow ();
1258 }
1259 
1260 extern void GetRidOfRedundantSourceNotes (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent);
1261 
CleanupGenbankBlockCallback(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)1262 static void CleanupGenbankBlockCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
1263 
1264 {
1265   BioseqPtr      bsp;
1266   BioseqSetPtr   bssp;
1267   Boolean        empty;
1268   GBBlockPtr     gbp;
1269   ValNodePtr     nextsdp;
1270   Pointer PNTR   prevsdp;
1271   ValNodePtr     sdp;
1272 
1273   if (sep == NULL || sep->data.ptrvalue == NULL) return;
1274   if (IS_Bioseq (sep)) {
1275     bsp = (BioseqPtr) sep->data.ptrvalue;
1276     sdp = bsp->descr;
1277     prevsdp = (Pointer PNTR) &(bsp->descr);
1278   } else if (IS_Bioseq_set (sep)) {
1279     bssp = (BioseqSetPtr) sep->data.ptrvalue;
1280     sdp = bssp->descr;
1281     prevsdp = (Pointer PNTR) &(bssp->descr);
1282   } else return;
1283   while (sdp != NULL) {
1284     nextsdp = sdp->next;
1285     empty = FALSE;
1286     if (sdp->choice == Seq_descr_genbank && sdp->data.ptrvalue == NULL) {
1287       empty = TRUE;
1288     } else if (sdp->choice == Seq_descr_genbank && sdp->data.ptrvalue != NULL) {
1289       gbp = (GBBlockPtr) sdp->data.ptrvalue;
1290       gbp->source = MemFree (gbp->source); /* remove within Sequin */
1291       gbp->origin = MemFree (gbp->origin);
1292       gbp->taxonomy = MemFree (gbp->taxonomy);
1293       if (gbp->extra_accessions == NULL && gbp->source == NULL &&
1294           gbp->keywords == NULL && gbp->origin == NULL &&
1295           gbp->date == NULL && gbp->entry_date == NULL &&
1296           gbp->div == NULL && gbp->taxonomy == NULL) {
1297         empty = TRUE;
1298       }
1299     }
1300     if (empty) {
1301       *(prevsdp) = sdp->next;
1302       sdp->next = NULL;
1303       SeqDescFree (sdp);
1304     } else {
1305       prevsdp = (Pointer PNTR) &(sdp->next);
1306     }
1307     sdp = nextsdp;
1308   }
1309 }
1310 
CheckBioSourceForEnvironmentalSample(BioSourcePtr biop,Pointer userdata)1311 static void CheckBioSourceForEnvironmentalSample (BioSourcePtr biop, Pointer userdata)
1312 {
1313   BoolPtr bp;
1314 
1315   if (biop == NULL || userdata == NULL) return;
1316 
1317   bp = (BoolPtr) userdata;
1318   if (! *bp) return;
1319 
1320   if (biop->org == NULL || biop->org->orgname == NULL)
1321   {
1322   	*bp = FALSE;
1323   	return;
1324   }
1325   if (StringSearch (biop->org->orgname->lineage, "environmental sample") == NULL)
1326   {
1327   	*bp = FALSE;
1328   }
1329 }
1330 
CheckForEnvironmentalSample(BioseqSetPtr bssp)1331 static Boolean CheckForEnvironmentalSample (BioseqSetPtr bssp)
1332 {
1333   Boolean all_enviro = TRUE;
1334 
1335   if (bssp == NULL) return FALSE;
1336 
1337   VisitBioSourcesInSet (bssp, (Pointer) &all_enviro, CheckBioSourceForEnvironmentalSample);
1338 
1339   return all_enviro;
1340 }
1341 
1342 
ConvertToEcoSets(SeqEntryPtr sep)1343 static void ConvertToEcoSets (SeqEntryPtr sep)
1344 {
1345   BioseqSetPtr bssp;
1346   SeqEntryPtr  sep_entry;
1347 
1348   if (sep == NULL) return;
1349 
1350   if (!IS_Bioseq_set (sep)) return;
1351   bssp = (BioseqSetPtr) sep->data.ptrvalue;
1352   if (bssp == NULL) return;
1353 
1354   if (bssp->_class == BioseqseqSet_class_mut_set
1355       || bssp->_class == BioseqseqSet_class_pop_set
1356       || bssp->_class == BioseqseqSet_class_phy_set)
1357   {
1358   	if (CheckForEnvironmentalSample (bssp))
1359   	{
1360   	  bssp->_class = BioseqseqSet_class_eco_set;
1361   	}
1362   }
1363   for (sep_entry = bssp->seq_set; sep_entry != NULL; sep_entry = sep_entry->next)
1364   {
1365   	if (IS_Bioseq_set (sep_entry))
1366   	{
1367   	  ConvertToEcoSets (sep_entry);
1368   	}
1369   }
1370 }
1371 
AddQualsFromLineageAndDiv(BioSourcePtr biop,Pointer userdata)1372 static void AddQualsFromLineageAndDiv (BioSourcePtr biop, Pointer userdata)
1373 {
1374   ValNode      vn;
1375 
1376   if (biop == NULL || biop->org == NULL || biop->org->orgname == NULL) return;
1377 
1378   if (StringISearch (biop->org->orgname->lineage, "environmental sample") != NULL
1379       || StringCmp (biop->org->orgname->div, "ENV") == 0)
1380   {
1381     vn.choice = SourceQualChoice_textqual;
1382     vn.data.intvalue = Source_qual_environmental_sample;
1383     vn.next = NULL;
1384     SetSourceQualInBioSource (biop, &vn, NULL, "", ExistingTextOption_replace_old);
1385   }
1386   if (StringISearch (biop->org->orgname->lineage, "metagenomes") != NULL) {
1387     vn.choice = SourceQualChoice_textqual;
1388     vn.data.intvalue = Source_qual_metagenomic;
1389     vn.next = NULL;
1390     SetSourceQualInBioSource (biop, &vn, NULL, "", ExistingTextOption_replace_old);
1391   }
1392 }
1393 
1394 
FixEasilyFixedSpecificHostValues(SeqEntryPtr sep)1395 static void FixEasilyFixedSpecificHostValues(SeqEntryPtr sep)
1396 {
1397   ValNodePtr fix_list, vnp;
1398   SpecificHostFixPtr s;
1399 
1400   fix_list = Taxon3GetSpecificHostFixesInSeqEntry (sep, TRUE, FALSE);
1401   for (vnp = fix_list; vnp != NULL; vnp = vnp->next)
1402   {
1403     s = (SpecificHostFixPtr) vnp->data.ptrvalue;
1404     if (s == NULL || StringHasNoText (s->bad_specific_host)) continue;
1405     if (s->fix_type == eSpecificHostFix_spelling || s->fix_type == eSpecificHostFix_capitalization) {
1406       ApplyOneSpecificHostFix (vnp->data.ptrvalue);
1407     }
1408   }
1409 }
1410 
1411 
ForceCleanupEntityID(Uint2 entityID)1412 extern void ForceCleanupEntityID (Uint2 entityID)
1413 
1414 {
1415   SeqEntryPtr   sep;
1416   ModTextFixPtr tfp;
1417 
1418   sep = GetTopSeqEntryForEntityID (entityID);
1419   if (sep == NULL) return;
1420   SeqMgrClearFeatureIndexes (entityID, NULL);
1421   SeqEntryExplore (sep, NULL, CleanupGenbankBlockCallback);
1422   SeqEntryExplore (sep, NULL, CleanupEmptyFeatCallback);
1423   SeqEntryExplore (sep, NULL, MergeAdjacentAnnotsCallback);
1424   MySeqEntryToAsn3 (sep, TRUE, FALSE, TRUE);
1425   CorrectGenCodes (sep, entityID);
1426   CleanUpPseudoProducts (entityID, sep);
1427   SeqEntryExplore (sep, NULL, GetRidOfRedundantSourceNotes);
1428   RenormalizeNucProtSets (sep, TRUE);
1429   CdCheck (sep, NULL);
1430   ConvertToEcoSets (sep);
1431   VisitBioSourcesInSep (sep, NULL, AddQualsFromLineageAndDiv);
1432   tfp = ModTextFixNew ();
1433   VisitBioSourcesInSep (sep, tfp, RemoveTextFromTextFreeSubSourceModifiers);
1434   FixEasilyFixedSpecificHostValues(sep);
1435 
1436   MemFree (tfp);
1437   ObjMgrSetDirtyFlag (entityID, TRUE);
1438   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
1439   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1440 }
1441 
ForceCleanupBtn(IteM i,ButtoN b,Boolean validate)1442 static void ForceCleanupBtn (IteM i, ButtoN b, Boolean validate)
1443 
1444 {
1445   BaseFormPtr   bfp;
1446 
1447   if (b != NULL) {
1448     bfp = GetObjectExtra (b);
1449   } else {
1450 #ifdef WIN_MAC
1451     bfp = currentFormDataPtr;
1452 #else
1453     bfp = GetObjectExtra (i);
1454 #endif
1455   }
1456   if (bfp == NULL) return;
1457   ForceCleanupEntityID (bfp->input_entityID);
1458   if (validate) {
1459     ValSeqEntryForm (bfp->form);
1460   }
1461 }
1462 
1463 
ForceCleanup(IteM i)1464 static void ForceCleanup (IteM i)
1465 
1466 {
1467   ForceCleanupBtn (i, NULL, TRUE);
1468 }
1469 
1470 
CorrectBothStrands(SeqFeatPtr sfp,Pointer userdata)1471 static void CorrectBothStrands (SeqFeatPtr sfp, Pointer userdata)
1472 
1473 {
1474   SeqLocPtr  location, slp = NULL;
1475   SeqIntPtr  sint;
1476   SeqPntPtr  spp;
1477 
1478   if (sfp == NULL) return;
1479   location = sfp->location;
1480   if (location == NULL) return;
1481 
1482   while ((slp = SeqLocFindNext (location, slp)) != NULL) {
1483     switch (slp->choice) {
1484       case SEQLOC_INT :
1485         sint = (SeqIntPtr) slp->data.ptrvalue;
1486         if (sint != NULL) {
1487           if (sint->strand == Seq_strand_both) {
1488             sint->strand = Seq_strand_plus;
1489           } else if (sint->strand == Seq_strand_both_rev) {
1490             sint->strand = Seq_strand_minus;
1491           }
1492         }
1493         break;
1494       case SEQLOC_PNT :
1495         spp = (SeqPntPtr) slp->data.ptrvalue;
1496         if (spp != NULL) {
1497           if (spp->strand == Seq_strand_both) {
1498             spp->strand = Seq_strand_plus;
1499           } else if (spp->strand == Seq_strand_both_rev) {
1500             spp->strand = Seq_strand_minus;
1501           }
1502         }
1503         break;
1504       default :
1505         break;
1506     }
1507   }
1508 }
1509 
ConvertBothStrands(IteM i)1510 static void ConvertBothStrands (IteM i)
1511 
1512 {
1513   BaseFormPtr  bfp;
1514   SeqEntryPtr  sep;
1515 
1516 #ifdef WIN_MAC
1517   bfp = currentFormDataPtr;
1518 #else
1519   bfp = GetObjectExtra (i);
1520 #endif
1521   if (bfp == NULL) return;
1522   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1523   if (sep == NULL) return;
1524   VisitFeaturesInSep (sep, NULL, CorrectBothStrands);
1525   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1526   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1527   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1528 }
1529 
AssignFeatIDs(IteM i)1530 static void AssignFeatIDs (IteM i)
1531 
1532 {
1533   BaseFormPtr  bfp;
1534   SeqEntryPtr  sep;
1535 
1536 #ifdef WIN_MAC
1537   bfp = currentFormDataPtr;
1538 #else
1539   bfp = GetObjectExtra (i);
1540 #endif
1541   if (bfp == NULL) return;
1542   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1543   if (sep == NULL) return;
1544 
1545   AssignFeatureIDs (sep);
1546 
1547   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1548   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1549   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1550   Update ();
1551 }
1552 
ReassignFeatIDs(IteM i)1553 static void ReassignFeatIDs (IteM i)
1554 
1555 {
1556   MsgAnswer    ans;
1557   BaseFormPtr  bfp;
1558   SeqEntryPtr  sep;
1559 
1560 #ifdef WIN_MAC
1561   bfp = currentFormDataPtr;
1562 #else
1563   bfp = GetObjectExtra (i);
1564 #endif
1565   if (bfp == NULL) return;
1566   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1567   if (sep == NULL) return;
1568 
1569   ans = Message (MSG_OKC, "Are you sure you want to reassign feature identifiers?");
1570   if (ans == ANS_CANCEL) return;
1571 
1572   ReassignFeatureIDs (sep);
1573 
1574   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1575   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1576   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1577   Update ();
1578 }
1579 
UniqifyFeatIDs(IteM i)1580 static void UniqifyFeatIDs (IteM i)
1581 
1582 {
1583   MsgAnswer     ans;
1584   BaseFormPtr   bfp;
1585   BioseqSetPtr  bssp, bssp2;
1586   Int4          count;
1587   Int4          offset = 0;
1588   SeqEntryPtr   sep;
1589 
1590 #ifdef WIN_MAC
1591   bfp = currentFormDataPtr;
1592 #else
1593   bfp = GetObjectExtra (i);
1594 #endif
1595   if (bfp == NULL) return;
1596   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1597   if (sep == NULL) return;
1598 
1599   if (! IS_Bioseq_set (sep)) return;
1600   bssp = (BioseqSetPtr) sep->data.ptrvalue;
1601   if (bssp == NULL || bssp->_class != BioseqseqSet_class_genbank) return;
1602 
1603   /* chec for inner nested genbank set */
1604 
1605   sep = bssp->seq_set;
1606   if (IS_Bioseq_set (sep)) {
1607     bssp2 = (BioseqSetPtr) sep->data.ptrvalue;
1608     if (bssp2 != NULL && bssp2->_class == BioseqseqSet_class_genbank) {
1609       bssp = bssp2;
1610     }
1611   }
1612 
1613   ans = Message (MSG_OKC, "Are you sure you want to make merged feature identifiers unique?");
1614   if (ans == ANS_CANCEL) return;
1615 
1616   for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
1617     count = FindHighestFeatureID (sep);
1618     OffsetFeatureIDs (sep, offset);
1619     OffsetFeatureIDXrefs (sep, offset);
1620     offset += count;
1621   }
1622 
1623   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1624   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1625   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1626   Update ();
1627 }
1628 
ClearFeatIDsAndLinks(IteM i)1629 static void ClearFeatIDsAndLinks (IteM i)
1630 
1631 {
1632   MsgAnswer    ans;
1633   BaseFormPtr  bfp;
1634   SeqEntryPtr  sep;
1635 
1636 #ifdef WIN_MAC
1637   bfp = currentFormDataPtr;
1638 #else
1639   bfp = GetObjectExtra (i);
1640 #endif
1641   if (bfp == NULL) return;
1642   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1643   if (sep == NULL) return;
1644 
1645   ans = Message (MSG_YN, "Are you sure you want to remove feature IDs and links?");
1646   if (ans == ANS_NO) return;
1647 
1648   ClearFeatureIDs (sep);
1649 
1650   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1651   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1652   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1653   Update ();
1654 }
1655 
LinkByOverlap(IteM i)1656 static void LinkByOverlap (IteM i)
1657 
1658 {
1659   BaseFormPtr  bfp;
1660   SeqEntryPtr  sep;
1661 
1662 #ifdef WIN_MAC
1663   bfp = currentFormDataPtr;
1664 #else
1665   bfp = GetObjectExtra (i);
1666 #endif
1667   if (bfp == NULL) return;
1668   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1669   if (sep == NULL) return;
1670 
1671   LinkCDSmRNAbyOverlap (sep);
1672 
1673   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1674   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1675   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1676   Update ();
1677 }
1678 
LinkByProduct(IteM i)1679 static void LinkByProduct (IteM i)
1680 
1681 {
1682   BaseFormPtr  bfp;
1683   ValNodePtr   bsplist;
1684   SeqEntryPtr  sep;
1685 
1686 #ifdef WIN_MAC
1687   bfp = currentFormDataPtr;
1688 #else
1689   bfp = GetObjectExtra (i);
1690 #endif
1691   if (bfp == NULL) return;
1692   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1693   if (sep == NULL) return;
1694 
1695   bsplist = LockFarComponentsEx (sep, FALSE, TRUE, TRUE, NULL);
1696   LinkCDSmRNAbyProduct (sep);
1697   bsplist = UnlockFarComponents (bsplist);
1698 
1699   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1700   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1701   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1702   Update ();
1703 }
1704 
LinkByLabel(IteM i)1705 static void LinkByLabel (IteM i)
1706 
1707 {
1708   BaseFormPtr  bfp;
1709   ValNodePtr   bsplist;
1710   SeqEntryPtr  sep;
1711 
1712 #ifdef WIN_MAC
1713   bfp = currentFormDataPtr;
1714 #else
1715   bfp = GetObjectExtra (i);
1716 #endif
1717   if (bfp == NULL) return;
1718   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1719   if (sep == NULL) return;
1720 
1721   bsplist = LockFarComponentsEx (sep, FALSE, TRUE, TRUE, NULL);
1722   LinkCDSmRNAbyLabel (sep);
1723   bsplist = UnlockFarComponents (bsplist);
1724 
1725   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1726   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1727   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1728   Update ();
1729 }
1730 
1731 
LinkByLabelAndLocation(IteM i)1732 static void LinkByLabelAndLocation (IteM i)
1733 
1734 {
1735   BaseFormPtr  bfp;
1736   ValNodePtr   bsplist;
1737   SeqEntryPtr  sep;
1738 
1739 #ifdef WIN_MAC
1740   bfp = currentFormDataPtr;
1741 #else
1742   bfp = GetObjectExtra (i);
1743 #endif
1744   if (bfp == NULL) return;
1745   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1746   if (sep == NULL) return;
1747 
1748   bsplist = LockFarComponentsEx (sep, FALSE, TRUE, TRUE, NULL);
1749   LinkCDSmRNAbyLabelAndLocation (sep);
1750   bsplist = UnlockFarComponents (bsplist);
1751 
1752   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1753   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1754   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1755   Update ();
1756 }
1757 
1758 
LinkSelected(IteM i)1759 static void LinkSelected (IteM i)
1760 
1761 {
1762   BaseFormPtr   bfp;
1763   SeqEntryPtr   sep;
1764   SeqFeatPtr    sfp1, sfp2;
1765   SelStructPtr  ssp;
1766 
1767 #ifdef WIN_MAC
1768   bfp = currentFormDataPtr;
1769 #else
1770   bfp = GetObjectExtra (i);
1771 #endif
1772   if (bfp == NULL) return;
1773   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1774   if (sep == NULL) return;
1775 
1776   AssignFeatureIDs (sep);
1777 
1778   ssp = ObjMgrGetSelected ();
1779   if (ssp == NULL) {
1780     Message (MSG_OK, "No features selected");
1781     return;
1782   }
1783   if (ssp->itemtype != OBJ_SEQFEAT) {
1784     Message (MSG_OK, "Something other than a feature is selected");
1785     return;
1786   }
1787   sfp1 = SeqMgrGetDesiredFeature (ssp->entityID, NULL, ssp->itemID, 0, NULL, NULL);
1788   if (sfp1 == NULL) {
1789     Message (MSG_OK, "Unable to find selected feature");
1790     return;
1791   }
1792   ssp = ssp->next;
1793   if (ssp == NULL) {
1794     Message (MSG_OK, "Only one feature was selected, two must be selected");
1795     return;
1796   }
1797   if (ssp->itemtype != OBJ_SEQFEAT) {
1798     Message (MSG_OK, "Something other than a feature is selected");
1799     return;
1800   }
1801   sfp2 = SeqMgrGetDesiredFeature (ssp->entityID, NULL, ssp->itemID, 0, NULL, NULL);
1802   if (ssp->next != NULL) {
1803     Message (MSG_OK, "Only two features must be selected");
1804     return;
1805   }
1806   if (sfp2 == NULL) {
1807     Message (MSG_OK, "Unable to find selected feature");
1808     return;
1809   }
1810 
1811   LinkTwoFeatures (sfp1, sfp2);
1812   LinkTwoFeatures (sfp2, sfp1);
1813 
1814   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1815   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1816   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1817   Update ();
1818 }
1819 
SelCDSmRNALink(IteM i)1820 static void SelCDSmRNALink (IteM i)
1821 
1822 {
1823   Char            buf [32];
1824   ObjectIdPtr     oip;
1825   SeqFeatPtr      sfp;
1826   SelStructPtr    ssp;
1827   CharPtr         str = NULL;
1828   SeqFeatXrefPtr  xref;
1829 
1830   ssp = ObjMgrGetSelected ();
1831   if (ssp == NULL) {
1832     Message (MSG_OK, "No feature selected");
1833     return;
1834   }
1835   if (ssp->next != NULL) {
1836     Message (MSG_OK, "Only one feature must be selected");
1837     return;
1838   }
1839   if (ssp->itemtype != OBJ_SEQFEAT) {
1840     Message (MSG_OK, "Something other than a feature is selected");
1841     return;
1842   }
1843 
1844   sfp = SeqMgrGetDesiredFeature (ssp->entityID, NULL, ssp->itemID, 0, NULL, NULL);
1845   if (sfp == NULL) {
1846     Message (MSG_OK, "Unable to find selected feature");
1847     return;
1848   }
1849 
1850   for (xref = sfp->xref; xref != NULL; xref = xref->next) {
1851     if (xref->id.choice != 3) continue;
1852     oip = (ObjectIdPtr) xref->id.value.ptrvalue;
1853     if (oip != NULL) {
1854       if (StringDoesHaveText (oip->str)) {
1855         str = oip->str;
1856       } else {
1857         sprintf (buf, "%ld", (long) oip->id);
1858         str = buf;
1859       }
1860     }
1861   }
1862 
1863   if (str == NULL) {
1864     Message (MSG_OK, "Unable to extract feature ID xref");
1865     return;
1866   }
1867 
1868   sfp = SeqMgrGetFeatureByFeatID (ssp->entityID, NULL, str, NULL, NULL);
1869   if (sfp == NULL) {
1870     Message (MSG_OK, "Unable to find referenced feature");
1871     return;
1872   }
1873 
1874   ObjMgrAlsoSelect (sfp->idx.entityID, sfp->idx.itemID, OBJ_SEQFEAT, 0, NULL);
1875   ObjMgrSendMsg (OM_MSG_UPDATE, sfp->idx.entityID, 0, 0);
1876   Update ();
1877 }
1878 
1879 
MakeFeatIdXrefsFromProteinIdQualifiers(IteM i)1880 static void MakeFeatIdXrefsFromProteinIdQualifiers (IteM i)
1881 {
1882   BaseFormPtr   bfp;
1883   SeqEntryPtr   sep;
1884 
1885 #ifdef WIN_MAC
1886   bfp = currentFormDataPtr;
1887 #else
1888   bfp = GetObjectExtra (i);
1889 #endif
1890   if (bfp == NULL) return;
1891   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1892   if (sep == NULL) return;
1893 
1894   MakeFeatureXrefsFromProteinIdQuals (sep);
1895 
1896   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1897   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1898   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1899   Update ();
1900 }
1901 
1902 
MakeFeatIdXrefsFromTranscriptIdQualifiers(IteM i)1903 static void MakeFeatIdXrefsFromTranscriptIdQualifiers  (IteM i)
1904 {
1905   BaseFormPtr   bfp;
1906   SeqEntryPtr   sep;
1907 
1908 #ifdef WIN_MAC
1909   bfp = currentFormDataPtr;
1910 #else
1911   bfp = GetObjectExtra (i);
1912 #endif
1913   if (bfp == NULL) return;
1914   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1915   if (sep == NULL) return;
1916 
1917   MakeFeatureXrefsFromTranscriptIdQuals (sep);
1918 
1919   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1920   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1921   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1922   Update ();
1923 }
1924 
1925 
CompleteHalfFormedXrefPairs(IteM i)1926 static void CompleteHalfFormedXrefPairs  (IteM i)
1927 {
1928   BaseFormPtr   bfp;
1929   SeqEntryPtr   sep;
1930 
1931 #ifdef WIN_MAC
1932   bfp = currentFormDataPtr;
1933 #else
1934   bfp = GetObjectExtra (i);
1935 #endif
1936   if (bfp == NULL) return;
1937   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1938   if (sep == NULL) return;
1939 
1940   FinishHalfXrefs (sep);
1941 
1942   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1943   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1944   ObjMgrDeSelect (0, 0, 0, 0, NULL);
1945   Update ();
1946 }
1947 
1948 
ForceTaxonFixupBtn(IteM i,ButtoN b)1949 extern void ForceTaxonFixupBtn (IteM i, ButtoN b)
1950 
1951 {
1952   BaseFormPtr  bfp;
1953   SeqEntryPtr  sep;
1954 
1955   if (b != NULL) {
1956     bfp = GetObjectExtra (b);
1957   } else {
1958 #ifdef WIN_MAC
1959     bfp = currentFormDataPtr;
1960 #else
1961     bfp = GetObjectExtra (i);
1962 #endif
1963   }
1964   if (bfp == NULL) return;
1965   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1966   if (sep == NULL) return;
1967   /* SeqEntryExplore (sep, (Pointer) bfp, CleanupGenbankBlockCallback); */
1968   SeqEntryExplore (sep, NULL, CleanupEmptyFeatCallback);
1969   SeqEntryExplore (sep, NULL, MergeAdjacentAnnotsCallback);
1970   MySeqEntryToAsn3 (sep, TRUE, FALSE, TRUE);
1971   CorrectGenCodes (sep, bfp->input_entityID);
1972   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
1973   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1974 }
1975 
RemoveDuplicateFeatsAction(Uint2 entityID,RemoveDuplicateFeatureActionPtr data)1976 static Boolean RemoveDuplicateFeatsAction (Uint2 entityID, RemoveDuplicateFeatureActionPtr data)
1977 {
1978   SeqEntryPtr sep;
1979   Boolean     rval = FALSE;
1980   Int4            num_cds_with_product = 0, num_feat = 0;
1981   MsgAnswer       ans;
1982   ValNodePtr      delete_list, vnp;
1983   SeqFeatPtr      sfp;
1984 
1985   sep = GetTopSeqEntryForEntityID (entityID);
1986 
1987   delete_list = GetDuplicateFeaturesForRemoval (sep, data);
1988 
1989   if (delete_list == NULL) {
1990     Message (MSG_ERROR, "No duplicates found");
1991     return rval;
1992   }
1993 
1994   for (vnp = delete_list; vnp != NULL; vnp = vnp->next) {
1995     num_feat++;
1996     if ((sfp = vnp->data.ptrvalue) != NULL
1997         && sfp->data.choice == SEQFEAT_CDREGION
1998         && sfp->product != NULL) {
1999       num_cds_with_product++;
2000     }
2001   }
2002 
2003   if (num_cds_with_product > 0 && !data->remove_proteins) {
2004     ans = Message (MSG_YNC, "%d duplicate features found.  %d coding regions have protein products.  Remove protein products?",
2005                    num_feat, num_cds_with_product);
2006     if (ans == ANS_CANCEL) {
2007       delete_list = ValNodeFree (delete_list);
2008       return rval;
2009     } else if (ans == ANS_YES) {
2010       data->remove_proteins = TRUE;
2011     }
2012   }
2013 
2014   RemoveDuplicateFeaturesInList (delete_list, entityID, data->remove_proteins);
2015 
2016   ObjMgrSetDirtyFlag (entityID, TRUE);
2017   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
2018   rval = TRUE;
2019   return rval;
2020 }
2021 
2022 typedef struct dupfeatsfrm {
2023   FORM_MESSAGE_BLOCK
2024   DialoG dlg;
2025 } DupFeatsFrmData, PNTR DupFeatsFrmPtr;
2026 
2027 
DoRemoveDuplicateFeats(ButtoN b)2028 static void DoRemoveDuplicateFeats (ButtoN b)
2029 {
2030   DupFeatsFrmPtr frm;
2031   RemoveDuplicateFeatureActionPtr data;
2032 
2033   frm = (DupFeatsFrmPtr) GetObjectExtra (b);
2034 
2035   if (frm == NULL) {
2036     return;
2037   }
2038 
2039   data = (RemoveDuplicateFeatureActionPtr) DialogToPointer (frm->dlg);
2040 
2041   if (RemoveDuplicateFeatsAction (frm->input_entityID, data)) {
2042     Remove (frm->form);
2043   }
2044   data = RemoveDuplicateFeatureActionFree (data);
2045 }
2046 
2047 
RemoveDuplicateFeatsWithOptions(IteM i)2048 static void RemoveDuplicateFeatsWithOptions (IteM i)
2049 {
2050   BaseFormPtr  bfp;
2051   WindoW       w;
2052   GrouP        h, c;
2053   ButtoN       b;
2054   DupFeatsFrmPtr frm;
2055 
2056 #ifdef WIN_MAC
2057   bfp = currentFormDataPtr;
2058 #else
2059   bfp = GetObjectExtra (i);
2060 #endif
2061   if (bfp == NULL) return;
2062 
2063   frm = (DupFeatsFrmPtr) MemNew (sizeof (DupFeatsFrmData));
2064 
2065   w = FixedWindow (-50, -33, -10, -10, "Remove Duplicate Features", StdCloseWindowProc);
2066   SetObjectExtra (w, frm, StdCleanupExtraProc);
2067   h = HiddenGroup (w, -1, 0, NULL);
2068   SetGroupSpacing (h, 10, 10);
2069 
2070   frm->form = (ForM) w;
2071   frm->input_entityID = bfp->input_entityID;
2072 
2073   frm->dlg = RemoveDuplicateFeatActionDialog (h, TRUE, NULL, NULL);
2074 
2075   c = HiddenGroup (h, 2, 0, NULL);
2076   b = DefaultButton (c, "Accept", DoRemoveDuplicateFeats);
2077   SetObjectExtra (b, frm, NULL);
2078   PushButton (c, "Cancel", StdCancelButtonProc);
2079   AlignObjects (ALIGN_CENTER, (HANDLE) frm->dlg, (HANDLE) c, NULL);
2080 
2081   Show (w);
2082 }
2083 
2084 
NewRemoveDuplicateFeatsBaseForm(BaseFormPtr bfp,Uint2 featdef)2085 static void NewRemoveDuplicateFeatsBaseForm (BaseFormPtr bfp, Uint2 featdef)
2086 {
2087   RemoveDuplicateFeatureAction h;
2088 
2089   if (bfp == NULL) return;
2090 
2091   MemSet (&h, 0, sizeof (RemoveDuplicateFeatureAction));
2092   h.type = GetFeatureTypeFromFeatdef (featdef);
2093   h.case_sensitive = TRUE;
2094   h.ignore_partials = FALSE;
2095   h.remove_proteins = FALSE;
2096 
2097   RemoveDuplicateFeatsAction (bfp->input_entityID, &h);
2098 }
2099 
NewRemoveDuplicateFeatsMenuItem(IteM i,Uint2 featdef)2100 static void NewRemoveDuplicateFeatsMenuItem (IteM i, Uint2 featdef)
2101 
2102 {
2103   BaseFormPtr  bfp;
2104 
2105 #ifdef WIN_MAC
2106   bfp = currentFormDataPtr;
2107 #else
2108   bfp = GetObjectExtra (i);
2109 #endif
2110   if (bfp == NULL) return;
2111 
2112   NewRemoveDuplicateFeatsBaseForm (bfp, featdef);
2113 }
2114 
2115 
NewRemoveDuplicateFeatsAll(IteM i)2116 static void NewRemoveDuplicateFeatsAll (IteM i)
2117 {
2118   NewRemoveDuplicateFeatsMenuItem (i, FEATDEF_ANY);
2119 }
2120 
2121 
2122 
NewRemoveDuplicateFeatsButton(ButtoN b)2123 static void NewRemoveDuplicateFeatsButton (ButtoN b)
2124 
2125 {
2126   BaseFormPtr  bfp;
2127 
2128   bfp = GetObjectExtra (b);
2129   if (bfp == NULL) return;
2130 
2131   NewRemoveDuplicateFeatsBaseForm (bfp, FEATDEF_ANY);
2132 }
2133 
2134 
2135 /*
2136 static Boolean LIBCALLBACK RemoveGeneXrefsOnBioseqs (BioseqPtr bsp, SeqMgrBioseqContextPtr bcontext)
2137 
2138 {
2139   SeqFeatXrefPtr     curr;
2140   SeqMgrFeatContext  fcontext;
2141   GeneRefPtr         grp;
2142   GeneRefPtr         grpx;
2143   SeqFeatXrefPtr     PNTR last;
2144   SeqFeatXrefPtr     next;
2145   Boolean            redundantgenexref;
2146   SeqFeatPtr         sfp;
2147   SeqFeatPtr         sfpx;
2148   CharPtr            syn1;
2149   CharPtr            syn2;
2150 
2151   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
2152   while (sfp != NULL) {
2153     if (sfp->data.choice != SEQFEAT_GENE) {
2154       grp = SeqMgrGetGeneXref (sfp);
2155       if (grp != NULL && (! SeqMgrGeneIsSuppressed (grp))) {
2156         sfpx = SeqMgrGetOverlappingGene (sfp->location, NULL);
2157         if (sfpx != NULL && sfpx->data.choice == SEQFEAT_GENE) {
2158           grpx = (GeneRefPtr) sfpx->data.value.ptrvalue;
2159           if (grpx != NULL) {
2160             redundantgenexref = FALSE;
2161             if ((! StringHasNoText (grp->locus)) && (! StringHasNoText (grpx->locus))) {
2162               if ((StringICmp (grp->locus, grpx->locus) == 0)) {
2163                 redundantgenexref = TRUE;
2164               }
2165             } else if ((! StringHasNoText (grp->locus_tag)) && (! StringHasNoText (grpx->locus_tag))) {
2166               if ((StringICmp (grp->locus_tag, grpx->locus_tag) == 0)) {
2167                 redundantgenexref = TRUE;
2168               }
2169             } else if (grp->syn != NULL && grpx->syn != NULL) {
2170               syn1 = (CharPtr) grp->syn->data.ptrvalue;
2171               syn2 = (CharPtr) grpx->syn->data.ptrvalue;
2172               if ((! StringHasNoText (syn1)) && (! StringHasNoText (syn2))) {
2173                 if ((StringICmp (syn1, syn2) == 0)) {
2174                   redundantgenexref = TRUE;
2175                 }
2176               }
2177             }
2178             if (redundantgenexref) {
2179               last = (SeqFeatXrefPtr PNTR) &(sfp->xref);
2180               curr = sfp->xref;
2181               while (curr != NULL) {
2182                 next = curr->next;
2183                 if (curr->data.choice == SEQFEAT_GENE) {
2184                   *last = next;
2185                   curr->next = NULL;
2186                   SeqFeatXrefFree (curr);
2187                 } else {
2188                   last = &(curr->next);
2189                 }
2190                 curr = next;
2191               }
2192             }
2193           }
2194         }
2195       }
2196     }
2197     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext);
2198   }
2199 
2200   return TRUE;
2201 }
2202 */
2203 
2204 typedef struct dummysmfedata {
2205   Int4  max;
2206   Int4  num_at_max;
2207 } DummySmfeData, PNTR DummySmfePtr;
2208 
SQNDummySMFEProc(SeqFeatPtr sfp,SeqMgrFeatContextPtr context)2209 static Boolean LIBCALLBACK SQNDummySMFEProc (
2210   SeqFeatPtr sfp,
2211   SeqMgrFeatContextPtr context
2212 )
2213 
2214 
2215 {
2216   DummySmfePtr  dsp;
2217   Int4          len;
2218 
2219   if (sfp == NULL || context == NULL) return TRUE;
2220   dsp = context->userdata;
2221   if (dsp == NULL) return TRUE;
2222 
2223   len = SeqLocLen (sfp->location);
2224   if (len < dsp->max) {
2225     dsp->max = len;
2226     dsp->num_at_max = 1;
2227   } else if (len == dsp->max) {
2228     (dsp->num_at_max)++;
2229   }
2230 
2231   return TRUE;
2232 }
2233 
RemoveGeneXrefsOnBioseqs(BioseqPtr bsp,SeqMgrBioseqContextPtr bcontext)2234 NLM_EXTERN Boolean LIBCALLBACK RemoveGeneXrefsOnBioseqs (BioseqPtr bsp, SeqMgrBioseqContextPtr bcontext)
2235 
2236 {
2237   Int2               count;
2238   SeqFeatXrefPtr     curr;
2239   DummySmfeData      dsd;
2240   SeqMgrFeatContext  fcontext;
2241   GeneRefPtr         grp;
2242   GeneRefPtr         grpx;
2243   SeqFeatXrefPtr     PNTR last;
2244   SeqFeatXrefPtr     next;
2245   Boolean            redundantgenexref;
2246   SeqFeatPtr         sfp;
2247   SeqFeatPtr         sfpx;
2248   CharPtr            syn1, syn2;
2249 
2250   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
2251   while (sfp != NULL) {
2252     grp = SeqMgrGetGeneXref (sfp);
2253     if (grp != NULL && (! SeqMgrGeneIsSuppressed (grp))) {
2254       sfpx = SeqMgrGetOverlappingGene (sfp->location, NULL);
2255       if (sfpx != NULL && sfpx->data.choice == SEQFEAT_GENE) {
2256         grpx = (GeneRefPtr) sfpx->data.value.ptrvalue;
2257         if (grpx != NULL) {
2258 
2259           redundantgenexref = TRUE;
2260           if ((!StringHasNoText (grp->locus)) && (!StringHasNoText (grpx->locus))) {
2261             if ((StringICmp (grp->locus, grpx->locus) != 0)) {
2262               redundantgenexref = FALSE;
2263             }
2264           } else if (StringDoesHaveText (grp->locus_tag) && StringDoesHaveText (grp->locus_tag)) {
2265             if ((StringICmp (grp->locus_tag, grpx->locus_tag) != 0)) {
2266               redundantgenexref = FALSE;
2267             }
2268           } else if (grp->syn != NULL && grpx->syn != NULL) {
2269             syn1 = (CharPtr) grp->syn->data.ptrvalue;
2270             syn2 = (CharPtr) grpx->syn->data.ptrvalue;
2271             if ((!StringHasNoText (syn1)) && (!StringHasNoText (syn2))) {
2272               if ((StringICmp (syn1, syn2) != 0)) {
2273                 redundantgenexref = FALSE;
2274               }
2275             }
2276           }
2277 
2278           if (redundantgenexref) {
2279             MemSet ((Pointer) &dsd, 0, sizeof (DummySmfeData));
2280             dsd.max = INT4_MAX;
2281             dsd.num_at_max = 0;
2282             count = SeqMgrGetAllOverlappingFeatures (sfp->location, FEATDEF_GENE, NULL, 0,
2283                                                       LOCATION_SUBSET, (Pointer) &dsd, SQNDummySMFEProc);
2284 
2285             if (dsd.num_at_max < 2) {
2286               last = (SeqFeatXrefPtr PNTR) &(sfp->xref);
2287               curr = sfp->xref;
2288               while (curr != NULL) {
2289                 next = curr->next;
2290                 if (curr->data.choice == SEQFEAT_GENE) {
2291                   *last = next;
2292                   curr->next = NULL;
2293                   SeqFeatXrefFree (curr);
2294                 } else {
2295                   last = &(curr->next);
2296                 }
2297                 curr = next;
2298               }
2299             }
2300           }
2301         }
2302       }
2303     }
2304     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext);
2305   }
2306 
2307   return TRUE;
2308 }
2309 
RemoveGeneXrefs(IteM i)2310 static void RemoveGeneXrefs (IteM i)
2311 
2312 {
2313   BaseFormPtr  bfp;
2314   Uint2        entityID;
2315   SeqEntryPtr  sep;
2316 
2317 #ifdef WIN_MAC
2318   bfp = currentFormDataPtr;
2319 #else
2320   bfp = GetObjectExtra (i);
2321 #endif
2322   if (bfp == NULL) return;
2323   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2324   if (sep == NULL) return;
2325   entityID = SeqMgrIndexFeatures (bfp->input_entityID, NULL);
2326   if (entityID < 1) return;
2327   SeqMgrExploreBioseqs (entityID, 0, NULL, RemoveGeneXrefsOnBioseqs, TRUE, TRUE, TRUE);
2328   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2329   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2330 }
2331 
RemoveGeneXNoLC(SeqFeatPtr sfp,Pointer userdata)2332 static void RemoveGeneXNoLC (SeqFeatPtr sfp, Pointer userdata)
2333 
2334 {
2335   BioseqPtr       bsp;
2336   GeneRefPtr      grp;
2337   SeqFeatXrefPtr  curr;
2338   SeqFeatXrefPtr  PNTR last;
2339   SeqFeatXrefPtr  next;
2340 
2341   grp = SeqMgrGetGeneXref (sfp);
2342   if (grp == NULL || SeqMgrGeneIsSuppressed (grp)) return;
2343   if (StringHasNoText (grp->locus)) return;
2344   bsp = BioseqFindFromSeqLoc (sfp->location);
2345   if (bsp == NULL) return;
2346   if (SeqMgrGetFeatureByLabel (bsp, grp->locus, SEQFEAT_GENE, 0, NULL) != NULL) return;
2347   last = (SeqFeatXrefPtr PNTR) &(sfp->xref);
2348   curr = sfp->xref;
2349   while (curr != NULL) {
2350     next = curr->next;
2351     if (curr->data.choice == SEQFEAT_GENE) {
2352       *last = next;
2353       curr->next = NULL;
2354       SeqFeatXrefFree (curr);
2355     } else {
2356       last = &(curr->next);
2357     }
2358     curr = next;
2359   }
2360 }
2361 
RemoveGeneXrefsNoGene(IteM i)2362 static void RemoveGeneXrefsNoGene (IteM i)
2363 
2364 {
2365   BaseFormPtr  bfp;
2366   SeqEntryPtr  sep;
2367 
2368 #ifdef WIN_MAC
2369   bfp = currentFormDataPtr;
2370 #else
2371   bfp = GetObjectExtra (i);
2372 #endif
2373   if (bfp == NULL) return;
2374   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2375   if (sep == NULL) return;
2376   VisitFeaturesInSep (sep, NULL, RemoveGeneXNoLC);
2377   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2378   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2379 }
2380 
RemoveGeneXNoLT(SeqFeatPtr sfp,Pointer userdata)2381 static void RemoveGeneXNoLT (SeqFeatPtr sfp, Pointer userdata)
2382 
2383 {
2384   BioseqPtr       bsp;
2385   GeneRefPtr      grp;
2386   SeqFeatXrefPtr  curr;
2387   SeqFeatXrefPtr  PNTR last;
2388   SeqFeatXrefPtr  next;
2389 
2390   grp = SeqMgrGetGeneXref (sfp);
2391   if (grp == NULL || SeqMgrGeneIsSuppressed (grp)) return;
2392   if (StringHasNoText (grp->locus_tag)) return;
2393   bsp = BioseqFindFromSeqLoc (sfp->location);
2394   if (bsp == NULL) return;
2395   if (SeqMgrGetGeneByLocusTag (bsp, grp->locus_tag, NULL) != NULL) return;
2396   last = (SeqFeatXrefPtr PNTR) &(sfp->xref);
2397   curr = sfp->xref;
2398   while (curr != NULL) {
2399     next = curr->next;
2400     if (curr->data.choice == SEQFEAT_GENE) {
2401       *last = next;
2402       curr->next = NULL;
2403       SeqFeatXrefFree (curr);
2404     } else {
2405       last = &(curr->next);
2406     }
2407     curr = next;
2408   }
2409 }
2410 
RemoveGeneXrefsNoLocTag(IteM i)2411 static void RemoveGeneXrefsNoLocTag (IteM i)
2412 
2413 {
2414   BaseFormPtr  bfp;
2415   SeqEntryPtr  sep;
2416 
2417 #ifdef WIN_MAC
2418   bfp = currentFormDataPtr;
2419 #else
2420   bfp = GetObjectExtra (i);
2421 #endif
2422   if (bfp == NULL) return;
2423   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2424   if (sep == NULL) return;
2425   VisitFeaturesInSep (sep, NULL, RemoveGeneXNoLT);
2426   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2427   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2428 }
2429 
DoRemoveNSGeneXrefs(SeqFeatPtr sfp,Pointer userdata)2430 static void DoRemoveNSGeneXrefs (SeqFeatPtr sfp, Pointer userdata)
2431 
2432 {
2433   SeqFeatXrefPtr  curr;
2434   GeneRefPtr      grp;
2435   SeqFeatXrefPtr  PNTR last;
2436   SeqFeatXrefPtr  next;
2437 
2438   last = (SeqFeatXrefPtr PNTR) &(sfp->xref);
2439   curr = sfp->xref;
2440   while (curr != NULL) {
2441     next = curr->next;
2442     if (curr->data.choice == SEQFEAT_GENE) {
2443       grp = (GeneRefPtr) curr->data.value.ptrvalue;
2444       if (SeqMgrGeneIsSuppressed (grp)) {
2445         last = &(curr->next);
2446       } else {
2447         *last = next;
2448         curr->next = NULL;
2449         SeqFeatXrefFree (curr);
2450       }
2451     } else {
2452       last = &(curr->next);
2453     }
2454     curr = next;
2455   }
2456 }
2457 
RemoveNSGeneXrefs(IteM i)2458 static void RemoveNSGeneXrefs (IteM i)
2459 
2460 {
2461   BaseFormPtr  bfp;
2462   SeqEntryPtr  sep;
2463 
2464 #ifdef WIN_MAC
2465   bfp = currentFormDataPtr;
2466 #else
2467   bfp = GetObjectExtra (i);
2468 #endif
2469   if (bfp == NULL) return;
2470   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2471   if (sep == NULL) return;
2472   VisitFeaturesInSep (sep, NULL, DoRemoveNSGeneXrefs);
2473   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2474   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2475 }
2476 
DoRemoveGeneXrefs(SeqFeatPtr sfp,Pointer userdata)2477 static void DoRemoveGeneXrefs (SeqFeatPtr sfp, Pointer userdata)
2478 
2479 {
2480   SeqFeatXrefPtr  curr;
2481   SeqFeatXrefPtr  PNTR last;
2482   SeqFeatXrefPtr  next;
2483 
2484   last = (SeqFeatXrefPtr PNTR) &(sfp->xref);
2485   curr = sfp->xref;
2486   while (curr != NULL) {
2487     next = curr->next;
2488     if (curr->data.choice == SEQFEAT_GENE) {
2489       *last = next;
2490       curr->next = NULL;
2491       SeqFeatXrefFree (curr);
2492     } else {
2493       last = &(curr->next);
2494     }
2495     curr = next;
2496   }
2497 }
2498 
RemoveAllGeneXrefs(IteM i)2499 static void RemoveAllGeneXrefs (IteM i)
2500 
2501 {
2502   BaseFormPtr  bfp;
2503   SeqEntryPtr  sep;
2504 
2505 #ifdef WIN_MAC
2506   bfp = currentFormDataPtr;
2507 #else
2508   bfp = GetObjectExtra (i);
2509 #endif
2510   if (bfp == NULL) return;
2511   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2512   if (sep == NULL) return;
2513   VisitFeaturesInSep (sep, NULL, DoRemoveGeneXrefs);
2514   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2515   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2516 }
2517 
2518 typedef struct removegenexref
2519 {
2520   FORM_MESSAGE_BLOCK
2521   DialoG  feature_select;
2522   DialoG  constraints;
2523   DialoG  accept_cancel;
2524 
2525   ButtoN  suppressing;
2526   ButtoN  nonsuppressing;
2527   ButtoN  unnecessary;
2528 
2529   Boolean do_suppressing;
2530   Boolean do_nonsuppressing;
2531   Boolean do_unnecessary;
2532 } RemoveGeneXrefData, PNTR RemoveGeneXrefPtr;
2533 
RemoveGeneXrefsChangeNotify(Pointer userdata)2534 static void RemoveGeneXrefsChangeNotify (Pointer userdata)
2535 {
2536   RemoveGeneXrefPtr dlg;
2537   ValNodePtr        vnp;
2538   Boolean           do_enable = FALSE;
2539 
2540   dlg = (RemoveGeneXrefPtr) userdata;
2541   if (dlg == NULL)
2542   {
2543     return;
2544   }
2545 
2546   vnp = (ValNodePtr) DialogToPointer (dlg->feature_select);
2547   if (vnp != NULL)
2548   {
2549     ValNodeFree (vnp);
2550     if (GetStatus (dlg->suppressing)
2551         || GetStatus (dlg->nonsuppressing)
2552         || GetStatus (dlg->unnecessary))
2553     {
2554       do_enable = TRUE;
2555     }
2556   }
2557   if (do_enable)
2558   {
2559     EnableAcceptCancelDialogAccept (dlg->accept_cancel);
2560   }
2561   else
2562   {
2563     DisableAcceptCancelDialogAccept (dlg->accept_cancel);
2564   }
2565 }
2566 
RemoveGeneXrefsChangeBtn(ButtoN b)2567 static void RemoveGeneXrefsChangeBtn (ButtoN b)
2568 {
2569   RemoveGeneXrefPtr dlg;
2570 
2571   dlg = (RemoveGeneXrefPtr) GetObjectExtra (b);
2572   RemoveGeneXrefsChangeNotify (dlg);
2573 }
2574 
RemoveGeneXrefsClear(Pointer data)2575 static void RemoveGeneXrefsClear (Pointer data)
2576 {
2577   RemoveGeneXrefPtr dlg;
2578 
2579   dlg = (RemoveGeneXrefPtr) data;
2580   if (dlg == NULL) return;
2581 
2582   PointerToDialog (dlg->feature_select, NULL);
2583   PointerToDialog (dlg->constraints, NULL);
2584 }
2585 
RemoveGeneXrefsClearText(Pointer data)2586 static void RemoveGeneXrefsClearText (Pointer data)
2587 {
2588   RemoveGeneXrefPtr    dlg;
2589   FilterSetPtr          fsp;
2590 
2591   dlg = (RemoveGeneXrefPtr) data;
2592   if (dlg == NULL) return;
2593 
2594   fsp = DialogToPointer (dlg->constraints);
2595   FilterSetClearText (fsp);
2596   PointerToDialog (dlg->constraints, fsp);
2597   FilterSetFree (fsp);
2598 }
2599 
IsUnnecessaryGeneXref(SeqFeatPtr sfp,GeneRefPtr grp)2600 static Boolean IsUnnecessaryGeneXref (SeqFeatPtr sfp, GeneRefPtr grp)
2601 {
2602   SeqFeatPtr sfpx;
2603   GeneRefPtr grpx;
2604   Boolean    redundantgenexref = FALSE;
2605   CharPtr    syn1;
2606   CharPtr    syn2;
2607 
2608   if (sfp == NULL || grp == NULL || SeqMgrGeneIsSuppressed (grp))
2609   {
2610     return FALSE;
2611   }
2612 
2613   sfpx = SeqMgrGetOverlappingGene (sfp->location, NULL);
2614   if (sfpx == NULL || sfpx->data.choice != SEQFEAT_GENE)
2615   {
2616     return FALSE;
2617   }
2618 
2619   grpx = (GeneRefPtr) sfpx->data.value.ptrvalue;
2620   if (grpx == NULL)
2621   {
2622     return FALSE;
2623   }
2624 
2625   if (StringDoesHaveText (grp->locus_tag) && StringDoesHaveText (grpx->locus_tag)) {
2626     if (StringICmp (grp->locus_tag, grpx->locus_tag) == 0) {
2627       redundantgenexref = TRUE;
2628     }
2629   } else if (StringDoesHaveText (grp->locus) && StringDoesHaveText (grpx->locus)) {
2630     if (StringICmp (grp->locus, grpx->locus) == 0) {
2631       redundantgenexref = TRUE;
2632     }
2633   } else if (grp->syn != NULL && grpx->syn != NULL) {
2634     syn1 = (CharPtr) grp->syn->data.ptrvalue;
2635     syn2 = (CharPtr) grpx->syn->data.ptrvalue;
2636     if (StringDoesHaveText (syn1) && StringDoesHaveText (syn2)) {
2637       if (StringICmp (syn1, syn2) == 0) {
2638         redundantgenexref = TRUE;
2639       }
2640     }
2641   }
2642   return redundantgenexref;
2643 }
2644 
RemoveGeneXrefsCallback(SeqFeatPtr sfp,Pointer userdata,FilterSetPtr fsp)2645 static void RemoveGeneXrefsCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
2646 {
2647   RemoveGeneXrefPtr    dlg;
2648   SeqFeatXrefPtr       curr;
2649   GeneRefPtr           grp;
2650   SeqFeatXrefPtr       PNTR last;
2651   SeqFeatXrefPtr       next;
2652   Boolean              is_suppressed;
2653 
2654   if (sfp == NULL || userdata == NULL)
2655   {
2656     return;
2657   }
2658 
2659   dlg = (RemoveGeneXrefPtr) userdata;
2660 
2661   last = (SeqFeatXrefPtr PNTR) &(sfp->xref);
2662   curr = sfp->xref;
2663   while (curr != NULL) {
2664     next = curr->next;
2665     if (curr->data.choice == SEQFEAT_GENE) {
2666       grp = (GeneRefPtr) curr->data.value.ptrvalue;
2667       is_suppressed = SeqMgrGeneIsSuppressed (grp);
2668 
2669       if ((dlg->do_suppressing && is_suppressed)
2670           || (dlg->do_nonsuppressing && !is_suppressed)
2671           || (dlg->do_unnecessary && IsUnnecessaryGeneXref (sfp, grp)))
2672       {
2673         *last = next;
2674         curr->next = NULL;
2675         SeqFeatXrefFree (curr);
2676       }
2677       else
2678       {
2679         last = &(curr->next);
2680       }
2681     } else {
2682       last = &(curr->next);
2683     }
2684     curr = next;
2685   }
2686 
2687 }
2688 
RemoveGeneXrefsAction(Pointer userdata)2689 static Boolean RemoveGeneXrefsAction (Pointer userdata)
2690 {
2691   RemoveGeneXrefPtr    dlg;
2692   FilterSetPtr         fsp;
2693   SeqEntryPtr          sep;
2694   ValNodePtr           feature_type_list, vnp;
2695   Uint1                 feat_def_choice;
2696 
2697   if (userdata == NULL) return FALSE;
2698 
2699   dlg = (RemoveGeneXrefPtr) userdata;
2700 
2701   sep = GetTopSeqEntryForEntityID (dlg->input_entityID);
2702   if (sep == NULL) return FALSE;
2703 
2704   feature_type_list = (ValNodePtr) DialogToPointer (dlg->feature_select);
2705 
2706   if (feature_type_list == NULL)
2707   {
2708     return FALSE;
2709   }
2710 
2711   fsp = (FilterSetPtr) DialogToPointer (dlg->constraints);
2712 
2713   dlg->do_suppressing = GetStatus (dlg->suppressing);
2714   dlg->do_nonsuppressing = GetStatus (dlg->nonsuppressing);
2715   dlg->do_unnecessary = GetStatus (dlg->unnecessary);
2716 
2717   for (vnp = feature_type_list; vnp != NULL; vnp = vnp->next)
2718   {
2719     feat_def_choice = vnp->choice;
2720     if (feat_def_choice == 255)
2721     {
2722       feat_def_choice = 0;
2723     }
2724     OperateOnSeqEntryConstrainedObjects (sep, fsp,
2725                                          RemoveGeneXrefsCallback,
2726                                          NULL, 0, feat_def_choice, 0, dlg);
2727   }
2728 
2729   ValNodeFree (feature_type_list);
2730   FilterSetFree (fsp);
2731 
2732   ObjMgrSetDirtyFlag (dlg->input_entityID, TRUE);
2733   ObjMgrSendMsg (OM_MSG_UPDATE, dlg->input_entityID, 0, 0);
2734   Update ();
2735   return TRUE;
2736 }
2737 
NewRemoveGeneXrefs(IteM i)2738 static void NewRemoveGeneXrefs (IteM i)
2739 
2740 {
2741   BaseFormPtr       bfp;
2742   RemoveGeneXrefPtr dlg;
2743   WindoW            w;
2744   GrouP             h, k;
2745   SeqEntryPtr       sep;
2746 
2747 #ifdef WIN_MAC
2748   bfp = currentFormDataPtr;
2749 #else
2750   bfp = GetObjectExtra (i);
2751 #endif
2752   if (bfp == NULL) return;
2753 
2754   dlg = (RemoveGeneXrefPtr) MemNew (sizeof (RemoveGeneXrefData));
2755   if (dlg == NULL) return;
2756 
2757   w = FixedWindow (-50, -33, -10, -10, "Remove Gene Xrefs", StdCloseWindowProc);
2758   SetObjectExtra (w, dlg, StdCleanupExtraProc);
2759   dlg->form = (ForM) w;
2760   dlg->input_entityID = bfp->input_entityID;
2761 
2762   h = HiddenGroup (w, -1, 0, NULL);
2763   SetGroupSpacing (h, 10, 10);
2764 
2765   sep = GetTopSeqEntryForEntityID(bfp->input_entityID);
2766   dlg->feature_select =  FeatureSelectionDialogEx (h, TRUE, sep,
2767                                                  RemoveGeneXrefsChangeNotify,
2768                                                  dlg);
2769 
2770   k = NormalGroup (h, 0, 3, "Remove Gene Xrefs that are", programFont, NULL);
2771   dlg->suppressing = CheckBox (k, "Suppressing", RemoveGeneXrefsChangeBtn);
2772   SetObjectExtra (dlg->suppressing, dlg, NULL);
2773   dlg->nonsuppressing = CheckBox (k, "Non-Suppressing", RemoveGeneXrefsChangeBtn);
2774   SetObjectExtra (dlg->nonsuppressing, dlg, NULL);
2775   dlg->unnecessary = CheckBox (k, "Unnecessary", RemoveGeneXrefsChangeBtn);
2776   SetObjectExtra (dlg->unnecessary, dlg, NULL);
2777 
2778   dlg->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, FALSE, "Where feature text");
2779   dlg->accept_cancel = AcceptCancelDialog (h, RemoveGeneXrefsAction, NULL, RemoveGeneXrefsClear, RemoveGeneXrefsClearText, (Pointer)dlg, w);
2780   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->feature_select,
2781                               (HANDLE) k,
2782                               (HANDLE) dlg->constraints,
2783                               (HANDLE) dlg->accept_cancel, NULL);
2784 
2785   Show (w);
2786 }
2787 
DoRefreshGeneXrefs(SeqFeatPtr sfp,Pointer userdata)2788 static void DoRefreshGeneXrefs (SeqFeatPtr sfp, Pointer userdata)
2789 
2790 {
2791   SeqFeatXrefPtr    curr;
2792   GeneRefPtr        grp, grpfeat;
2793   SeqFeatPtr        gene;
2794   SeqMgrFeatContext fcontext;
2795   BioseqPtr         bsp;
2796 
2797   if (sfp == NULL) return;
2798 
2799   for (curr = sfp->xref; curr != NULL; curr = curr->next)
2800   {
2801     if (curr->data.choice == SEQFEAT_GENE) {
2802       grp = (GeneRefPtr) curr->data.value.ptrvalue;
2803       if (grp != NULL)
2804       {
2805         bsp = BioseqFindFromSeqLoc (sfp->location);
2806         gene = SeqMgrGetFeatureByLabel (bsp, grp->locus, SEQFEAT_GENE, 0, &fcontext);
2807         if (gene != NULL && gene->data.choice == SEQFEAT_GENE) {
2808           grpfeat = (GeneRefPtr) gene->data.value.ptrvalue;
2809           if (grpfeat != NULL) {
2810             GeneRefFree (grp);
2811             grp = GeneRefDup (grpfeat);
2812             curr->data.value.ptrvalue = grp;
2813           }
2814         }
2815       }
2816     }
2817   }
2818 }
2819 
RefreshGeneXRefs(IteM i)2820 static void RefreshGeneXRefs (IteM i)
2821 
2822 {
2823   BaseFormPtr  bfp;
2824   SeqEntryPtr  sep;
2825 
2826 #ifdef WIN_MAC
2827   bfp = currentFormDataPtr;
2828 #else
2829   bfp = GetObjectExtra (i);
2830 #endif
2831   if (bfp == NULL) return;
2832   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2833   if (sep == NULL) return;
2834   VisitFeaturesInSep (sep, NULL, DoRefreshGeneXrefs);
2835   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2836   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2837 }
2838 
RemoveDbxrefList(ValNodePtr vnp)2839 static ValNodePtr RemoveDbxrefList (ValNodePtr vnp)
2840 
2841 {
2842   ValNodePtr  next;
2843 
2844   while (vnp != NULL) {
2845     next = vnp->next;
2846     DbtagFree ((DbtagPtr) vnp->data.ptrvalue);
2847     MemFree (vnp);
2848     vnp = next;
2849   }
2850   return NULL;
2851 }
2852 
DoRemoveDbxrefs(SeqFeatPtr sfp,Pointer userdata)2853 static void DoRemoveDbxrefs (SeqFeatPtr sfp, Pointer userdata)
2854 
2855 {
2856   GeneRefPtr  grp;
2857   Uint1       feattype;
2858 
2859   if (sfp == NULL) return;
2860 
2861   if (userdata != NULL && (feattype = *(Uint1 PNTR)userdata) != sfp->data.choice) return;
2862   sfp->dbxref = RemoveDbxrefList (sfp->dbxref);
2863   if (sfp->data.choice != SEQFEAT_GENE) return;
2864   grp = (GeneRefPtr) sfp->data.value.ptrvalue;
2865   if (grp == NULL) return;
2866   grp->db = RemoveDbxrefList (grp->db);
2867 }
2868 
DoRemoveBioSourceDbxrefs(BioSourcePtr biop,Pointer userdata)2869 static void DoRemoveBioSourceDbxrefs (BioSourcePtr biop, Pointer userdata)
2870 {
2871   if (biop == NULL || biop->org == NULL) return;
2872 
2873   biop->org->db = RemoveDbxrefList (biop->org->db);
2874 }
2875 
RemoveDbxrefsCommon(IteM i,Uint1 PNTR subtype,Boolean remove_source,Boolean remove_features)2876 static void RemoveDbxrefsCommon (IteM i, Uint1 PNTR subtype, Boolean remove_source, Boolean remove_features)
2877 
2878 {
2879   BaseFormPtr  bfp;
2880   SeqEntryPtr  sep;
2881 
2882 #ifdef WIN_MAC
2883   bfp = currentFormDataPtr;
2884 #else
2885   bfp = GetObjectExtra (i);
2886 #endif
2887   if (bfp == NULL) return;
2888   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2889   if (sep == NULL) return;
2890   if (remove_features) {
2891     VisitFeaturesInSep (sep, subtype, DoRemoveDbxrefs);
2892   }
2893   if (subtype == NULL && remove_source)
2894   {
2895     VisitBioSourcesInSep (sep, NULL, DoRemoveBioSourceDbxrefs);
2896   }
2897   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2898   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2899 }
2900 
RemoveGeneDbxrefs(IteM i)2901 static void RemoveGeneDbxrefs (IteM i)
2902 {
2903   Uint1        subtype = SEQFEAT_GENE;
2904   RemoveDbxrefsCommon (i, &subtype, FALSE, TRUE);
2905 }
2906 
RemoveRNADbxrefs(IteM i)2907 static void RemoveRNADbxrefs (IteM i)
2908 
2909 {
2910   Uint1        subtype = SEQFEAT_RNA;
2911 
2912   RemoveDbxrefsCommon (i, &subtype, FALSE, TRUE);
2913 }
2914 
RemoveCDSDbxrefs(IteM i)2915 static void RemoveCDSDbxrefs (IteM i)
2916 
2917 {
2918   Uint1        subtype = FEATDEF_CDS;
2919   RemoveDbxrefsCommon (i, &subtype, FALSE, TRUE);
2920 }
2921 
RemoveAllFeatureDbxrefs(IteM i)2922 static void RemoveAllFeatureDbxrefs (IteM i)
2923 {
2924   RemoveDbxrefsCommon (i, NULL, FALSE, TRUE);
2925 }
2926 
RemoveAllDbxrefs(IteM i)2927 static void RemoveAllDbxrefs (IteM i)
2928 
2929 {
2930   RemoveDbxrefsCommon (i, NULL, TRUE, TRUE);
2931 }
2932 
2933 
RemoveAllBioSourceDbxrefs(IteM i)2934 static void RemoveAllBioSourceDbxrefs (IteM i)
2935 
2936 {
2937   RemoveDbxrefsCommon (i, NULL, TRUE, FALSE);
2938 }
2939 
2940 
RemoveMissingFeatureXrefsCallback(SeqFeatPtr sfp,Pointer data)2941 static void RemoveMissingFeatureXrefsCallback (SeqFeatPtr sfp, Pointer data)
2942 
2943 {
2944   SeqFeatXrefPtr  xref, xref_next, xref_prev = NULL;
2945   SeqFeatPtr      matchsfp;
2946 
2947   if (sfp == NULL) {
2948     return;
2949   }
2950 
2951   for (xref = sfp->xref; xref != NULL; xref = xref_next) {
2952     xref_next = xref->next;
2953     if (xref->id.choice != 0
2954         && (matchsfp = SeqMgrGetFeatureByFeatID (sfp->idx.entityID, NULL, NULL, xref, NULL)) == NULL) {
2955       if (xref_prev == NULL) {
2956         sfp->xref = xref->next;
2957       } else {
2958         xref_prev->next = xref->next;
2959       }
2960       xref->next = NULL;
2961       xref = SeqFeatXrefFree (xref);
2962     } else {
2963       xref_prev = xref;
2964     }
2965   }
2966 }
2967 
2968 
RemoveMissingFeatureXrefs(IteM i)2969 static void RemoveMissingFeatureXrefs (IteM i)
2970 
2971 {
2972   BaseFormPtr  bfp;
2973   SeqEntryPtr  sep;
2974 
2975 #ifdef WIN_MAC
2976   bfp = currentFormDataPtr;
2977 #else
2978   bfp = GetObjectExtra (i);
2979 #endif
2980   if (bfp == NULL) return;
2981   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2982   if (sep == NULL) return;
2983   WatchCursor();
2984   Update();
2985   VisitFeaturesInSep (sep, NULL, RemoveMissingFeatureXrefsCallback);
2986   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2987   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2988   ArrowCursor();
2989   Update();
2990 }
2991 
2992 
RemoveSelFeats(IteM i)2993 static void RemoveSelFeats (IteM i)
2994 
2995 {
2996   MsgAnswer          ans;
2997   BaseFormPtr        bfp;
2998   BioseqPtr          cdna;
2999   SeqMgrFeatContext  fcontext;
3000   BioseqPtr          prot;
3001   Boolean            remove_asked;
3002   Boolean            remove_mrnas = FALSE;
3003   Boolean            remove_prots = FALSE;
3004   SelStructPtr       sel;
3005   SeqEntryPtr        sep;
3006   SeqFeatPtr         sfp;
3007   SelStructPtr       ssp;
3008   Boolean            unremoved_feats = FALSE;
3009 
3010 #ifdef WIN_MAC
3011   bfp = currentFormDataPtr;
3012 #else
3013   bfp = GetObjectExtra (i);
3014 #endif
3015   if (bfp == NULL) return;
3016   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3017   if (sep == NULL) return;
3018 
3019   ssp = ObjMgrGetSelected ();
3020   if (ssp == NULL) return;
3021 
3022   remove_asked = FALSE;
3023   for (sel = ssp; sel != NULL; sel = sel->next) {
3024     if (sel->entityID != bfp->input_entityID)
3025     {
3026       unremoved_feats = TRUE;
3027       continue;
3028     }
3029     if (sel->itemtype == OBJ_SEQFEAT) {
3030       sfp = SeqMgrGetDesiredFeature (sel->entityID, NULL, sel->itemID, 0, NULL, &fcontext);
3031       if (sfp != NULL) {
3032         sfp->idx.deleteme = TRUE;
3033         if (sfp->data.choice == SEQFEAT_CDREGION && sfp->product != NULL) {
3034           prot = BioseqFindFromSeqLoc (sfp->product);
3035           if (prot != NULL) {
3036             if (! remove_asked) {
3037               ans = Message (MSG_YN, "Remove protein products?");
3038               if (ans == ANS_YES) {
3039                 remove_prots = TRUE;
3040               }
3041               remove_asked = TRUE;
3042             }
3043             if (remove_prots) {
3044               prot->idx.deleteme = TRUE;
3045             }
3046           }
3047         }
3048       }
3049     }
3050   }
3051 
3052   remove_asked = FALSE;
3053   for (sel = ssp; sel != NULL; sel = sel->next) {
3054     if (sel->entityID != bfp->input_entityID)
3055     {
3056       unremoved_feats = TRUE;
3057       continue;
3058     }
3059     if (sel->itemtype == OBJ_SEQFEAT) {
3060       sfp = SeqMgrGetDesiredFeature (sel->entityID, NULL, sel->itemID, 0, NULL, &fcontext);
3061       if (sfp != NULL) {
3062         sfp->idx.deleteme = TRUE;
3063         if (sfp->data.choice == SEQFEAT_RNA && sfp->product != NULL) {
3064           cdna = BioseqFindFromSeqLoc (sfp->product);
3065           if (cdna != NULL) {
3066             if (! remove_asked) {
3067               ans = Message (MSG_YN, "Remove mRNA products?");
3068               if (ans == ANS_YES) {
3069                 remove_mrnas = TRUE;
3070               }
3071               remove_asked = TRUE;
3072             }
3073             if (remove_mrnas) {
3074               cdna->idx.deleteme = TRUE;
3075             }
3076           }
3077         }
3078       }
3079     }
3080   }
3081 
3082   ObjMgrSelect (0, 0, 0, 0, NULL);
3083 
3084   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
3085 
3086   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3087   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3088   if (unremoved_feats)
3089   {
3090     Message (MSG_ERROR, "Warning!  Features mapped to far sequences cannot be deleted!");
3091   }
3092 }
3093 
RemoveUnselFeats(IteM i)3094 static void RemoveUnselFeats (IteM i)
3095 
3096 {
3097   MsgAnswer          ans;
3098   BaseFormPtr        bfp;
3099   BioseqPtr          bsp;
3100   BioseqPtr          cdna;
3101   SeqMgrFeatContext  fcontext;
3102   BioseqPtr          prot;
3103   Boolean            remove_asked;
3104   Boolean            remove_mrnas = FALSE;
3105   Boolean            remove_prots = FALSE;
3106   SelStructPtr       sel;
3107   SeqEntryPtr        sep;
3108   SeqFeatPtr         sfp;
3109   SelStructPtr       ssp;
3110   SeqEntryPtr        scope;
3111   Boolean            sel_on_local = FALSE;
3112   Boolean            sel_on_far = FALSE;
3113 
3114 #ifdef WIN_MAC
3115   bfp = currentFormDataPtr;
3116 #else
3117   bfp = GetObjectExtra (i);
3118 #endif
3119   if (bfp == NULL) return;
3120   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3121   if (sep == NULL) return;
3122 
3123   ssp = ObjMgrGetSelected ();
3124   if (ssp == NULL) return;
3125 
3126   scope = SeqEntrySetScope (NULL);
3127   bsp = NULL;
3128   for (sel = ssp; sel != NULL && bsp == NULL; sel = sel->next) {
3129     if (sel->entityID != bfp->input_entityID)
3130     {
3131       if (sel->itemtype == OBJ_SEQFEAT)
3132       {
3133         sel_on_far = TRUE;
3134       }
3135       continue;
3136     }
3137     if (sel->itemtype == OBJ_SEQFEAT) {
3138       sel_on_local = TRUE;
3139       sfp = SeqMgrGetDesiredFeature (sel->entityID, NULL, sel->itemID, 0, NULL, &fcontext);
3140       if (sfp != NULL) {
3141         bsp = BioseqFindFromSeqLoc (sfp->location);
3142       }
3143     }
3144   }
3145   SeqEntrySetScope (scope);
3146   if (bsp == NULL)
3147   {
3148     if (sel_on_far && ! sel_on_local)
3149     {
3150       Message (MSG_ERROR, "Warning!  Features mapped to far sequences cannot be deleted!");
3151     }
3152     return;
3153   }
3154 
3155   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
3156   while (sfp != NULL) {
3157     sfp->idx.deleteme = TRUE;
3158     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext);
3159   }
3160 
3161   for (sel = ssp; sel != NULL; sel = sel->next) {
3162     if (sel->entityID != bfp->input_entityID) continue;
3163     if (sel->itemtype == OBJ_SEQFEAT) {
3164       sfp = SeqMgrGetDesiredFeature (0, bsp, sel->itemID, 0, NULL, &fcontext);
3165       if (sfp != NULL) {
3166         sfp->idx.deleteme = FALSE;
3167       }
3168     }
3169   }
3170 
3171   remove_asked = FALSE;
3172   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
3173   while (sfp != NULL) {
3174     if (sfp->idx.deleteme) {
3175       if (sfp->data.choice == SEQFEAT_CDREGION && sfp->product != NULL) {
3176         prot = BioseqFindFromSeqLoc (sfp->product);
3177         if (prot != NULL) {
3178           if (! remove_asked) {
3179             ans = Message (MSG_YN, "Remove protein products?");
3180             if (ans == ANS_YES) {
3181               remove_prots = TRUE;
3182             }
3183             remove_asked = TRUE;
3184           }
3185           if (remove_prots) {
3186             prot->idx.deleteme = TRUE;
3187           }
3188         }
3189       }
3190     }
3191     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext);
3192   }
3193 
3194   remove_asked = FALSE;
3195   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
3196   while (sfp != NULL) {
3197     if (sfp->idx.deleteme) {
3198       if (sfp->data.choice == SEQFEAT_RNA && sfp->product != NULL) {
3199         cdna = BioseqFindFromSeqLoc (sfp->product);
3200         if (cdna != NULL) {
3201           if (! remove_asked) {
3202             ans = Message (MSG_YN, "Remove mRNA products?");
3203             if (ans == ANS_YES) {
3204               remove_mrnas = TRUE;
3205             }
3206             remove_asked = TRUE;
3207           }
3208           if (remove_mrnas) {
3209             cdna->idx.deleteme = TRUE;
3210           }
3211         }
3212       }
3213     }
3214     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext);
3215   }
3216 
3217   ObjMgrSelect (0, 0, 0, 0, NULL);
3218 
3219   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
3220 
3221   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3222   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3223 }
3224 
RemoveFeatsOutOfSelRange(IteM i)3225 static void RemoveFeatsOutOfSelRange (IteM i)
3226 
3227 {
3228   MsgAnswer          ans;
3229   BaseFormPtr        bfp;
3230   BioseqPtr          bsp;
3231   BioseqPtr          cdna;
3232   SeqMgrFeatContext  fcontext;
3233   BioseqPtr          prot;
3234   Boolean            remove_asked;
3235   Boolean            remove_mrnas = FALSE;
3236   Boolean            remove_prots = FALSE;
3237   SelStructPtr       sel;
3238   SeqEntryPtr        sep;
3239   SeqFeatPtr         sfp;
3240   SeqLocPtr          slp = NULL;
3241   SelStructPtr       ssp;
3242   SeqEntryPtr        scope;
3243   Boolean            sel_on_local = FALSE;
3244   Boolean            sel_on_far = FALSE;
3245 
3246 #ifdef WIN_MAC
3247   bfp = currentFormDataPtr;
3248 #else
3249   bfp = GetObjectExtra (i);
3250 #endif
3251   if (bfp == NULL) return;
3252   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3253   if (sep == NULL) return;
3254 
3255   ssp = ObjMgrGetSelected ();
3256   if (ssp == NULL) {
3257     Message (MSG_ERROR, "Warning!  No features are selected - please select one");
3258     return;
3259   }
3260   if (ssp->next != NULL) {
3261     Message (MSG_ERROR, "Warning!  Multiple features are selected - please select only one");
3262     return;
3263   }
3264 
3265   scope = SeqEntrySetScope (NULL);
3266   bsp = NULL;
3267   for (sel = ssp; sel != NULL && bsp == NULL; sel = sel->next) {
3268     if (sel->entityID != bfp->input_entityID)
3269     {
3270       if (sel->itemtype == OBJ_SEQFEAT)
3271       {
3272         sel_on_far = TRUE;
3273       }
3274       continue;
3275     }
3276     if (sel->itemtype == OBJ_SEQFEAT) {
3277       sel_on_local = TRUE;
3278       sfp = SeqMgrGetDesiredFeature (sel->entityID, NULL, sel->itemID, 0, NULL, &fcontext);
3279       if (sfp != NULL) {
3280         slp = sfp->location;
3281         bsp = BioseqFindFromSeqLoc (slp);
3282       }
3283     }
3284   }
3285   SeqEntrySetScope (scope);
3286   if (bsp == NULL)
3287   {
3288     if (sel_on_far && ! sel_on_local)
3289     {
3290       Message (MSG_ERROR, "Warning!  Please select only a feature on a near sequence");
3291     }
3292     return;
3293   }
3294   if (slp == NULL) {
3295     Message (MSG_ERROR, "Warning!  Failure to get location from selected feature");
3296     return;
3297   }
3298 
3299   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
3300   while (sfp != NULL) {
3301     if (SeqLocAinB (sfp->location, slp) >= 0) {
3302       sfp->idx.deleteme = FALSE;
3303     } else {
3304       sfp->idx.deleteme = TRUE;
3305     }
3306     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext);
3307   }
3308 
3309   remove_asked = FALSE;
3310   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
3311   while (sfp != NULL) {
3312     if (sfp->idx.deleteme) {
3313       if (sfp->data.choice == SEQFEAT_CDREGION && sfp->product != NULL) {
3314         prot = BioseqFindFromSeqLoc (sfp->product);
3315         if (prot != NULL) {
3316           if (! remove_asked) {
3317             ans = Message (MSG_YN, "Remove protein products?");
3318             if (ans == ANS_YES) {
3319               remove_prots = TRUE;
3320             }
3321             remove_asked = TRUE;
3322           }
3323           if (remove_prots) {
3324             prot->idx.deleteme = TRUE;
3325           }
3326         }
3327       }
3328     }
3329     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext);
3330   }
3331 
3332   remove_asked = FALSE;
3333   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
3334   while (sfp != NULL) {
3335     if (sfp->idx.deleteme) {
3336       if (sfp->data.choice == SEQFEAT_RNA && sfp->product != NULL) {
3337         cdna = BioseqFindFromSeqLoc (sfp->product);
3338         if (cdna != NULL) {
3339           if (! remove_asked) {
3340             ans = Message (MSG_YN, "Remove mRNA products?");
3341             if (ans == ANS_YES) {
3342               remove_mrnas = TRUE;
3343             }
3344             remove_asked = TRUE;
3345           }
3346           if (remove_mrnas) {
3347             cdna->idx.deleteme = TRUE;
3348           }
3349         }
3350       }
3351     }
3352     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext);
3353   }
3354 
3355   ObjMgrSelect (0, 0, 0, 0, NULL);
3356 
3357   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
3358 
3359   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3360   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3361 }
3362 
RemoveCDDRegions(IteM i)3363 static void RemoveCDDRegions (IteM i)
3364 
3365 {
3366   BaseFormPtr  bfp;
3367   SeqEntryPtr  sep;
3368 
3369 #ifdef WIN_MAC
3370   bfp = currentFormDataPtr;
3371 #else
3372   bfp = GetObjectExtra (i);
3373 #endif
3374   if (bfp == NULL) return;
3375   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3376   if (sep == NULL) return;
3377   FreeCDDRegions (sep);
3378   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3379   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3380 }
3381 
RemoveCDDAligns(IteM i)3382 static void RemoveCDDAligns (IteM i)
3383 
3384 {
3385   BaseFormPtr  bfp;
3386   SeqEntryPtr  sep;
3387 
3388 #ifdef WIN_MAC
3389   bfp = currentFormDataPtr;
3390 #else
3391   bfp = GetObjectExtra (i);
3392 #endif
3393   if (bfp == NULL) return;
3394   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3395   if (sep == NULL) return;
3396   FreeCDDAligns (sep);
3397   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3398   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3399 }
3400 
RemoveCDDDups(IteM i)3401 static void RemoveCDDDups (IteM i)
3402 
3403 {
3404   BaseFormPtr  bfp;
3405   SeqEntryPtr  sep;
3406 
3407 #ifdef WIN_MAC
3408   bfp = currentFormDataPtr;
3409 #else
3410   bfp = GetObjectExtra (i);
3411 #endif
3412   if (bfp == NULL) return;
3413   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3414   if (sep == NULL) return;
3415   RemoveDuplicateCDDs (sep);
3416   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3417   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3418 }
3419 
RetainBestCDD(IteM i)3420 static void RetainBestCDD (IteM i)
3421 
3422 {
3423   BaseFormPtr  bfp;
3424   SeqEntryPtr  sep;
3425 
3426 #ifdef WIN_MAC
3427   bfp = currentFormDataPtr;
3428 #else
3429   bfp = GetObjectExtra (i);
3430 #endif
3431   if (bfp == NULL) return;
3432   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3433   if (sep == NULL) return;
3434   LeaveBestCDD (sep);
3435   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3436   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3437 }
3438 
3439 
TryReplacingUnderscoresWithSpaces(BioSourcePtr biop)3440 static void TryReplacingUnderscoresWithSpaces (BioSourcePtr biop)
3441 {
3442   CharPtr orgname;
3443   CharPtr cp;
3444   Int4    taxID;
3445 
3446   if (biop == NULL || biop->org == NULL || StringHasNoText (biop->org->taxname)
3447       || HasTaxonomyID (biop)) {
3448     return;
3449   }
3450   cp = StringChr (biop->org->taxname, '_');
3451   if (cp == NULL) {
3452     return;
3453   }
3454   orgname = StringSave (biop->org->taxname);
3455   cp = StringChr (orgname, '_');
3456   *cp = ' ';
3457   taxID = Taxon3GetTaxIdByName (orgname);
3458   while (taxID < 1 && cp != NULL) {
3459     *cp = '_';
3460     cp = StringChr (cp + 1, '_');
3461     if (cp != NULL) {
3462       *cp = ' ';
3463       taxID = Taxon3GetTaxIdByName (orgname);
3464     }
3465   }
3466   if (taxID > 0) {
3467     SetTaxNameAndRemoveTaxRef (biop->org, orgname);
3468     orgname = NULL;
3469   }
3470   orgname = MemFree (orgname);
3471 }
3472 
3473 
LastDitchLookup(BioSourcePtr biop)3474 static void LastDitchLookup (BioSourcePtr biop)
3475 
3476 {
3477   CharPtr       orgname;
3478   OrgRefPtr     orp;
3479   CharPtr       ptr;
3480   CharPtr       binomial_end = NULL, trinomial_end = NULL;
3481   SubSourcePtr  ssp;
3482   Int4          taxID;
3483 
3484   /* if this organism has already been assigned a taxon ID or has no taxname, skip it */
3485   if (biop == NULL
3486       || (orp = biop->org) == NULL
3487       || StringHasNoText (orp->taxname)
3488       || HasTaxonomyID (biop)) {
3489     return;
3490   }
3491 
3492   /* we are looking for a name that might become a recognizable name if we
3493    * truncated it after the first four words (if the third word is subsp.),
3494    * after the first three words (if the third word is not subsp.),
3495    * or after the first two words if the above two attempts failed.
3496    */
3497   orgname = StringSave (orp->taxname);
3498   ptr = StringChr (orgname, ' ');
3499   if (ptr == NULL) {
3500     /* if there is only one word, all we can do is look for underscores
3501      * and see if we can get a recognizable name by replacing underscores
3502      * with spaces.
3503      */
3504     TryReplacingUnderscoresWithSpaces (biop);
3505     orgname = MemFree (orgname);
3506     return;
3507   }
3508   /* skip over the first word and the spaces after it. */
3509   while (*ptr == ' ')
3510   {
3511     ptr++;
3512   }
3513   ptr = StringChr (ptr, ' ');
3514   /* if there are only two words, give up. */
3515   if (ptr == NULL)
3516   {
3517     orgname = MemFree (orgname);
3518     return;
3519   }
3520   binomial_end = ptr;
3521   while (*ptr == ' ')
3522   {
3523     ptr++;
3524   }
3525   if (StringNCmp (ptr, "subsp.", 6) == 0)
3526   {
3527     ptr += 6;
3528     while (*ptr == ' ' )
3529     {
3530       ptr++;
3531     }
3532   }
3533 
3534   ptr = StringChr (ptr, ' ');
3535   if (ptr != NULL)
3536   {
3537     trinomial_end = ptr;
3538   }
3539 
3540   /* see if trinomial produces a tax server hit */
3541   taxID = 0;
3542   if (trinomial_end != NULL)
3543   {
3544     *trinomial_end = '\0';
3545     taxID = Taxon3GetTaxIdByName (orgname);
3546   }
3547   if (taxID < 1)
3548   {
3549     /* see if binomial produces a tax server hit */
3550     *binomial_end = '\0';
3551     taxID = Taxon3GetTaxIdByName (orgname);
3552   }
3553 
3554   if (taxID > 0) {
3555     /* create a note that contains the original name of the organism, and truncate
3556      * the actual organism after the binomial or trinomial.
3557      */
3558     ssp = SubSourceNew ();
3559     if (ssp != NULL) {
3560       ssp->subtype = 255;
3561       ssp->name = orp->taxname;
3562       orp->taxname = NULL;
3563       ssp->next = biop->subtype;
3564       biop->subtype = ssp;
3565       SetTaxNameAndRemoveTaxRef (orp, orgname);
3566       orgname = NULL;
3567     }
3568   }
3569   orgname = MemFree (orgname);
3570 }
3571 
LastDitchTaxonFixup(SeqEntryPtr sep,Pointer data,Int4 index,Int2 indent)3572 static void LastDitchTaxonFixup (SeqEntryPtr sep, Pointer data, Int4 index, Int2 indent)
3573 
3574 {
3575 	BioseqPtr bsp = NULL;
3576 	BioseqSetPtr bssp = NULL;
3577 	ValNodePtr descr, vnp;
3578 	BioSourcePtr biosp = NULL;
3579 	SeqAnnotPtr annot, sap;
3580 	SeqFeatPtr sfp;
3581 
3582 	if (IS_Bioseq(sep)) {
3583 		bsp = sep->data.ptrvalue;
3584 		descr = bsp->descr;
3585 		annot = bsp->annot;
3586 	} else {
3587 		bssp = sep->data.ptrvalue;
3588 		descr = bssp->descr;
3589 		annot = bssp->annot;
3590 	}
3591 	for (vnp = descr; vnp; vnp = vnp->next) {
3592 		if (vnp->choice == Seq_descr_source) {
3593 			biosp = vnp->data.ptrvalue;
3594 			LastDitchLookup (biosp);
3595 		}
3596 	}
3597 	for (sap = annot; sap != NULL; sap = sap->next) {
3598 		if (sap->type == 1) {
3599 			for (sfp = (SeqFeatPtr) sap->data; sfp != NULL; sfp = sfp->next) {
3600 				if (sfp->data.choice == SEQFEAT_BIOSRC) {
3601 					biosp = sfp->data.value.ptrvalue;
3602 					LastDitchLookup (biosp);
3603 				}
3604 			}
3605 		}
3606 	}
3607 }
3608 
GenSpecTaxonFixup(IteM i)3609 static void GenSpecTaxonFixup (IteM i)
3610 
3611 {
3612   BaseFormPtr  bfp;
3613   SeqEntryPtr  sep;
3614 
3615 #ifdef WIN_MAC
3616   bfp = currentFormDataPtr;
3617 #else
3618   bfp = GetObjectExtra (i);
3619 #endif
3620   if (bfp == NULL) return;
3621   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3622   if (sep == NULL) return;
3623   SeqEntryExplore (sep, NULL, LastDitchTaxonFixup);
3624   ForceTaxonFixupBtn (i, NULL);
3625 }
3626 
3627 
MergeToPartsCallback(SeqFeatPtr sfp,Pointer userdata)3628 static void MergeToPartsCallback (SeqFeatPtr sfp, Pointer userdata)
3629 {
3630   BoolPtr ordered;
3631 
3632   if (sfp == NULL) return;
3633   ordered = (BoolPtr) userdata;
3634 
3635   MergeFeatureIntervalsToParts (sfp, *ordered);
3636 }
3637 
MergeToParts(IteM i,Boolean ordered)3638 static void MergeToParts (IteM i, Boolean ordered)
3639 {
3640   BaseFormPtr       bfp;
3641   SelStructPtr      ssp;
3642   Boolean           some_sel_not_feat = FALSE;
3643   Boolean           some_sel_feat = FALSE;
3644   SeqFeatPtr        sfp;
3645   SeqMgrFeatContext fcontext;
3646   SeqEntryPtr       sep;
3647 
3648   ssp = ObjMgrGetSelected ();
3649   if (ssp == NULL) {
3650 #ifdef WIN_MAC
3651     bfp = currentFormDataPtr;
3652 #else
3653     bfp = GetObjectExtra (i);
3654 #endif
3655     if (bfp == NULL) {
3656       Message (MSG_ERROR, "MergeToParts error");
3657       return;
3658     }
3659     sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3660     if (sep == NULL) return;
3661     VisitFeaturesInSep (sep, (Pointer) &ordered, MergeToPartsCallback);
3662     ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3663     ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3664   }
3665   else
3666   {
3667     while (ssp != NULL)
3668     {
3669       if (ssp->itemtype == OBJ_SEQFEAT)
3670       {
3671         sfp = SeqMgrGetDesiredFeature (ssp->entityID, NULL, ssp->itemID, 0, NULL, &fcontext);
3672         if (sfp != NULL)
3673         {
3674           MergeFeatureIntervalsToParts (sfp, ordered);
3675           some_sel_feat = TRUE;
3676           ObjMgrSetDirtyFlag (ssp->entityID, TRUE);
3677           ObjMgrSendMsg (OM_MSG_UPDATE, ssp->entityID, 0, 0);
3678         }
3679       }
3680       else
3681       {
3682         some_sel_not_feat = TRUE;
3683       }
3684       ssp = ssp->next;
3685     }
3686     if (!some_sel_feat)
3687     {
3688       Message (MSG_ERROR, "No features selected!");
3689     }
3690     else if (some_sel_not_feat)
3691     {
3692       Message (MSG_ERROR, "Some selected items were not features!");
3693     }
3694   }
3695   Update ();
3696 }
3697 
MergeToPartsJoin(IteM i)3698 extern void MergeToPartsJoin (IteM i)
3699 {
3700   MergeToParts (i, FALSE);
3701 }
3702 
MergeToPartsOrdered(IteM i)3703 extern void MergeToPartsOrdered (IteM i)
3704 {
3705   MergeToParts (i, TRUE);
3706 }
3707 
3708 
MergeSegSeqCallback(GatherContextPtr gcp)3709 static Boolean MergeSegSeqCallback (GatherContextPtr gcp)
3710 
3711 {
3712   BioseqPtr     bsp;
3713   CodeBreakPtr  cbp;
3714   CdRegionPtr   crp;
3715   Boolean       noLeft;
3716   Boolean       noRight;
3717   RnaRefPtr     rrp;
3718   SeqEntryPtr   sep;
3719   SeqFeatPtr    sfp;
3720   SeqLocPtr     slp;
3721   tRNAPtr       trna;
3722 
3723   if (gcp->thistype != OBJ_SEQFEAT) return TRUE;
3724   sfp = (SeqFeatPtr) gcp->thisitem;
3725   if (sfp == NULL || sfp->location == NULL) return TRUE;
3726   bsp = GetBioseqGivenSeqLoc (sfp->location, gcp->entityID);
3727   if (bsp == NULL) return TRUE;
3728   if (ISA_aa (bsp->mol)) return TRUE;
3729   if (bsp->repr != Seq_repr_seg) {
3730     sep = GetBestTopParentForData (gcp->entityID, bsp);
3731     if (sep == NULL) return TRUE;
3732     sep = FindNucSeqEntry (sep);
3733     if (sep == NULL || sep->choice != 1) return TRUE;
3734     bsp = (BioseqPtr) sep->data.ptrvalue;
3735     if (bsp == NULL) return TRUE;
3736   }
3737   CheckSeqLocForPartial (sfp->location, &noLeft, &noRight);
3738   slp = SeqLocMerge (bsp, sfp->location, NULL, FALSE, TRUE, FALSE);
3739   if (slp == NULL) return TRUE;
3740   sfp->location = SeqLocFree (sfp->location);
3741   sfp->location = slp;
3742   FreeAllFuzz (sfp->location);
3743   SetSeqLocPartial (sfp->location, noLeft, noRight);
3744   sfp->partial = (sfp->partial || noLeft || noRight);
3745   switch (sfp->data.choice) {
3746     case SEQFEAT_CDREGION :
3747       crp = (CdRegionPtr) sfp->data.value.ptrvalue;
3748       if (crp != NULL && crp->code_break != NULL) {
3749         for (cbp = crp->code_break; cbp != NULL; cbp = cbp->next) {
3750           slp = SeqLocMerge (bsp, cbp->loc, NULL, FALSE, TRUE, FALSE);
3751           if (slp != NULL) {
3752             cbp->loc = SeqLocFree (cbp->loc);
3753             cbp->loc = slp;
3754             FreeAllFuzz (cbp->loc);
3755           }
3756         }
3757       }
3758       break;
3759     case SEQFEAT_RNA :
3760       rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
3761       if (rrp != NULL && rrp->type == 3 && rrp->ext.choice == 2) {
3762         trna = rrp->ext.value.ptrvalue;
3763         if (trna != NULL && trna->anticodon != NULL) {
3764           slp = SeqLocMerge (bsp, trna->anticodon, NULL, FALSE, TRUE, FALSE);
3765           if (slp != NULL) {
3766             trna->anticodon = SeqLocFree (trna->anticodon);
3767             trna->anticodon = slp;
3768             FreeAllFuzz (trna->anticodon);
3769           }
3770         }
3771       }
3772       break;
3773     default :
3774       break;
3775   }
3776   return TRUE;
3777 }
3778 
MergeToSegSeq(IteM i)3779 static void MergeToSegSeq (IteM i)
3780 
3781 {
3782   BaseFormPtr   bfp;
3783   GatherScope   gs;
3784   SelStructPtr  ssp;
3785 
3786   ssp = ObjMgrGetSelected ();
3787   if (ssp == NULL) {
3788 #ifdef WIN_MAC
3789     bfp = currentFormDataPtr;
3790 #else
3791     bfp = GetObjectExtra (i);
3792 #endif
3793     if (bfp == NULL) {
3794       Message (MSG_ERROR, "MergeToSegSeq error");
3795       return;
3796     }
3797     MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
3798     gs.seglevels = 1;
3799     MemSet((Pointer)(gs.ignore), (int)(TRUE), (size_t)(OBJ_MAX * sizeof(Boolean)));
3800     gs.ignore[OBJ_BIOSEQ] = FALSE;
3801     gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
3802     gs.ignore[OBJ_SEQANNOT] = FALSE;
3803     gs.ignore[OBJ_SEQFEAT] = FALSE;
3804     GatherEntity (bfp->input_entityID, NULL, MergeSegSeqCallback, &gs);
3805     ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3806     ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3807     /*
3808     Message (MSG_ERROR, "No item selected");
3809     */
3810     return;
3811   }
3812   if (ssp->itemtype != OBJ_SEQFEAT) {
3813     Message (MSG_ERROR, "Feature must be selected");
3814     return;
3815   }
3816   GatherItem (ssp->entityID, ssp->itemID, ssp->itemtype, NULL, MergeSegSeqCallback);
3817   ObjMgrSetDirtyFlag (ssp->entityID, TRUE);
3818   ObjMgrSendMsg (OM_MSG_UPDATE, ssp->entityID, 0, 0);
3819 }
3820 
SegToRawCallback(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)3821 static void SegToRawCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
3822 
3823 {
3824   BioseqPtr  bsp;
3825 
3826   if (sep == NULL) return;
3827   if (! IS_Bioseq (sep)) return;
3828   bsp = (BioseqPtr) sep->data.ptrvalue;
3829   if (bsp == NULL || (bsp->repr != Seq_repr_seg && bsp->repr != Seq_repr_delta)) return;
3830   SegOrDeltaBioseqToRaw (bsp);
3831 }
3832 
SegSeqToRawSeq(IteM i)3833 static void SegSeqToRawSeq (IteM i)
3834 
3835 {
3836   BaseFormPtr  bfp;
3837   SeqEntryPtr  sep;
3838 
3839 #ifdef WIN_MAC
3840   bfp = currentFormDataPtr;
3841 #else
3842   bfp = GetObjectExtra (i);
3843 #endif
3844   if (bfp == NULL) return;
3845   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3846   if (sep == NULL) return;
3847   SeqEntryExplore (sep, (Pointer) bfp, SegToRawCallback);
3848   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3849   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3850 }
3851 
CollectBioseqsForConversion(BioseqPtr bsp,Pointer userdata)3852 static void CollectBioseqsForConversion (BioseqPtr bsp, Pointer userdata)
3853 {
3854   ValNodePtr PNTR list;
3855 
3856   if (bsp == NULL || bsp->repr != Seq_repr_raw || ISA_aa (bsp->mol)) return;
3857   if (userdata == NULL)
3858   {
3859     return;
3860   }
3861   list = (ValNodePtr PNTR) userdata;
3862 
3863   ValNodeAddPointer (list, 0, bsp);
3864 }
3865 
GetAnnotListForBspList(ValNodePtr bsp_list)3866 static ValNodePtr GetAnnotListForBspList (ValNodePtr bsp_list)
3867 {
3868   BioseqPtr   bsp;
3869   SeqAnnotPtr sanp;
3870   ValNodePtr  complete_annot_list = NULL, align_annot_list;
3871   ValNodePtr  annot_vnp, vnp, bsp_vnp;
3872   Boolean     found;
3873 
3874   for (bsp_vnp = bsp_list; bsp_vnp != NULL; bsp_vnp = bsp_vnp->next)
3875   {
3876     bsp = (BioseqPtr)(bsp_vnp->data.ptrvalue);
3877     align_annot_list = FindAlignSeqAnnotsForBioseq (bsp);
3878     for (annot_vnp = align_annot_list; annot_vnp != NULL; annot_vnp = annot_vnp->next)
3879     {
3880       sanp = (SeqAnnotPtr) annot_vnp->data.ptrvalue;
3881       if (sanp->type == 2 && sanp->data != NULL)
3882       {
3883         for (vnp = complete_annot_list, found = FALSE;
3884              vnp != NULL && !found;
3885              vnp = vnp->next)
3886         {
3887           if (vnp->data.ptrvalue == sanp)
3888           {
3889             found = TRUE;
3890           }
3891         }
3892         if (!found)
3893         {
3894           ValNodeAddPointer (&complete_annot_list, 0, sanp);
3895         }
3896       }
3897     }
3898     align_annot_list = ValNodeFree (align_annot_list);
3899   }
3900   return complete_annot_list;
3901 }
3902 
3903 
3904 static void
CleanupAlignmentsAfterConversion(ValNodePtr adjusted_bsp_list,Uint2 entityID)3905 CleanupAlignmentsAfterConversion
3906 (ValNodePtr adjusted_bsp_list,
3907  Uint2 entityID)
3908 {
3909   ValNodePtr  align_annot_list, annot_vnp;
3910   SeqAnnotPtr sanp;
3911 
3912   align_annot_list = GetAnnotListForBspList (adjusted_bsp_list);
3913   for (annot_vnp = align_annot_list;
3914        annot_vnp != NULL;
3915        annot_vnp = annot_vnp->next)
3916   {
3917     sanp = annot_vnp->data.ptrvalue;
3918     if (sanp != NULL && sanp->type == 2)
3919     {
3920       ConsolidateSegmentsOverKnownLengthGaps (sanp->data);
3921       FixOneAlignmentOverGaps (sanp->data, entityID);
3922     }
3923   }
3924   align_annot_list = ValNodeFree (align_annot_list);
3925   DeleteMarkedObjects (entityID, 0, NULL);
3926 
3927 }
3928 
3929 
3930 typedef struct linkageinfo {
3931   Uint1 linkage_type;
3932   Uint1 linkage_evidence;
3933   Uint1 linkage_linkage;
3934 } LinkageInfoData, PNTR LinkageInfoPtr;
3935 
3936 
AddLinkageInfoToBioseq(BioseqPtr bsp,Pointer data)3937 static void AddLinkageInfoToBioseq (BioseqPtr bsp, Pointer data)
3938 {
3939   LinkageInfoPtr lp;
3940   DeltaSeqPtr    dsp;
3941   SeqLitPtr      slip;
3942   SeqGapPtr      sgp;
3943   LinkageEvidencePtr link;
3944 
3945   if (bsp == NULL || bsp->repr != Seq_repr_delta || bsp->seq_ext == NULL || (lp = (LinkageInfoPtr) data) == NULL) {
3946     return;
3947   }
3948 
3949   for (dsp = (DeltaSeqPtr)(bsp->seq_ext); dsp != NULL; dsp = dsp->next) {
3950     if (dsp->choice == 2) {
3951       slip = (SeqLitPtr)(dsp->data.ptrvalue);
3952       if (slip != NULL) {
3953         if (slip->seq_data == NULL) {
3954           slip->seq_data_type = Seq_code_gap;
3955           slip->seq_data = (SeqDataPtr)SeqGapNew ();
3956         }
3957         if (slip->seq_data_type == Seq_code_gap) {
3958           sgp = (SeqGapPtr) slip->seq_data;
3959           sgp->type = lp->linkage_type;
3960           if (lp->linkage_type == 9) {
3961             sgp->linkage = 1;
3962           } else if (lp->linkage_type == 7) {
3963             sgp->linkage = lp->linkage_linkage;
3964           }
3965           if (sgp->linkage == 1) {
3966             link = LinkageEvidenceNew ();
3967             link->type = lp->linkage_evidence;
3968             ValNodeAddPointer (&(sgp->linkage_evidence), 0, link);
3969           }
3970         }
3971       }
3972     }
3973   }
3974 }
3975 
3976 
ConvertNsToGapsWithSizeList(Uint2 entityID,Int4Ptr gap_sizes,Boolean adjust_cds,LinkageInfoPtr lp)3977 static void ConvertNsToGapsWithSizeList (Uint2 entityID, Int4Ptr gap_sizes, Boolean adjust_cds, LinkageInfoPtr lp)
3978 {
3979   ValNodePtr  adjusted_bsp_list = NULL;
3980   SeqEntryPtr sep;
3981 
3982   sep = GetTopSeqEntryForEntityID (entityID);
3983   if (sep == NULL) return;
3984   VisitBioseqsInSep (sep, &adjusted_bsp_list, CollectBioseqsForConversion);
3985 
3986   if (adjust_cds)
3987   {
3988     /* remove the gap locations from the coding regions first */
3989     VisitBioseqsInSep (sep, gap_sizes, PrepareCodingRegionLocationsForDeltaConversionCallback);
3990   }
3991 
3992   VisitBioseqsInSep (sep, gap_sizes, ConvertNsToGaps);
3993   if (lp != NULL) {
3994     VisitBioseqsInSep (sep, lp, AddLinkageInfoToBioseq);
3995   }
3996   CleanupAlignmentsAfterConversion (adjusted_bsp_list, entityID);
3997   adjusted_bsp_list = ValNodeFree (adjusted_bsp_list);
3998   ObjMgrSetDirtyFlag (entityID, TRUE);
3999   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
4000 }
4001 
4002 
4003 #if 0
4004 static void ConvertSegSetToDeltaItem (IteM i)
4005 {
4006   BaseFormPtr  bfp;
4007   SeqEntryPtr  sep;
4008   Int4         gap_sizes[2];
4009 
4010 #ifdef WIN_MAC
4011   bfp = currentFormDataPtr;
4012 #else
4013   bfp = GetObjectExtra (i);
4014 #endif
4015   if (bfp == NULL) return;
4016   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
4017   if (sep == NULL) return;
4018   ConvertSegSetsToDeltaSequences (sep);
4019   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
4020   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
4021 }
4022 #endif
4023 
4024 
4025 /* dialog for linkage info */
4026 typedef struct linkageinfodlg {
4027   DIALOG_MESSAGE_BLOCK
4028   PopuP  linkage_type;
4029   PopuP  linkage_evidence;
4030   PopuP  linkage_linkage;
4031 } LinkageInfoDlg, PNTR LinkageInfoDlgPtr;
4032 
ENUM_ALIST(linkage_type_alist)4033 static ENUM_ALIST(linkage_type_alist)
4034 {"unknown",         0   },
4035 {"short-arm",       3   },
4036 {"heterochromatin", 4   },
4037 {"centromere",      5   },
4038 {"telomere",        6   },
4039 {"repeat",          7   },
4040 {"between",         8   },
4041 {"within",          9   },
4042 /*{"other",           255 }, */
4043 END_ENUM_ALIST
4044 
4045 static ENUM_ALIST(linkage_evidence_alist)
4046 {"paired-ends",     0   },
4047 {"align-genus",     1   },
4048 {"align-xgenus",    2   },
4049 {"align-trnscpt",   3   },
4050 {"within-clone",    4   },
4051 {"clone-contig",    5   },
4052 {"map",             6   },
4053 {"strobe",          7   },
4054 {"unspecified",     8   },
4055 {"pcr",             9   },
4056 /*{"other",           255 },*/
4057 END_ENUM_ALIST
4058 
4059 static Pointer LinkageInfoDialogToPointer (DialoG d)
4060 {
4061     LinkageInfoDlgPtr dlg;
4062     LinkageInfoPtr lp;
4063     UIEnum           val;
4064 
4065     dlg = (LinkageInfoDlgPtr) GetObjectExtra(d);
4066     if (dlg == NULL) {
4067         return NULL;
4068     }
4069     lp = (LinkageInfoPtr) MemNew (sizeof (LinkageInfoData));
4070     GetEnumPopup (dlg->linkage_type, linkage_type_alist, &val);
4071     lp->linkage_type = val;
4072     if (val == 9) {
4073       GetEnumPopup (dlg->linkage_evidence, linkage_evidence_alist, &val);
4074       lp->linkage_evidence = val;
4075     } else if (val == 7) {
4076       if (GetValue(dlg->linkage_linkage) == 1) {
4077         lp->linkage_linkage = 1;
4078         GetEnumPopup (dlg->linkage_evidence, linkage_evidence_alist, &val);
4079         lp->linkage_evidence = val;
4080       } else {
4081         lp->linkage_linkage = 0;
4082       }
4083     }
4084     return (Pointer) lp;
4085 }
4086 
4087 
ChangeGapType(PopuP p)4088 static void ChangeGapType(PopuP p)
4089 {
4090   LinkageInfoDlgPtr dlg;
4091   UIEnum           val;
4092   Int2             val2;
4093 
4094   dlg = (LinkageInfoDlgPtr) GetObjectExtra (p);
4095   if (dlg == NULL) {
4096     return;
4097   }
4098 
4099   /* enable or disable linkage evidence */
4100   GetEnumPopup (dlg->linkage_type, linkage_type_alist, &val);
4101   if (val == 9) {
4102     Enable (dlg->linkage_evidence);
4103   } else if (val == 7) {
4104     val2 = GetValue(dlg->linkage_linkage);
4105     if (val2 == 1) {
4106       Enable (dlg->linkage_evidence);
4107     } else {
4108       Disable (dlg->linkage_evidence);
4109     }
4110   } else {
4111     Disable (dlg->linkage_evidence);
4112   }
4113 
4114   /* enable or disable linkage */
4115   if (val == 7) {
4116     Enable (dlg->linkage_linkage);
4117   } else {
4118     Disable (dlg->linkage_linkage);
4119   }
4120 }
4121 
4122 
4123 
LinkageInfoDialog(GrouP parent)4124 extern DialoG LinkageInfoDialog (GrouP parent)
4125 {
4126   LinkageInfoDlgPtr dlg;
4127   GrouP           p;
4128 
4129   dlg = (LinkageInfoDlgPtr) MemNew (sizeof (LinkageInfoDlg));
4130   if (dlg == NULL)
4131   {
4132     return NULL;
4133   }
4134 
4135   p = HiddenGroup (parent, 2, 0, NULL);
4136   SetGroupSpacing(p, 10, 10);
4137   SetObjectExtra (p, dlg, StdCleanupExtraProc);
4138 
4139   dlg->dialog = (DialoG) p;
4140   dlg->todialog = NULL;
4141   dlg->fromdialog = LinkageInfoDialogToPointer;
4142   dlg->dialogmessage = NULL;
4143   dlg->testdialog = NULL;
4144 
4145   StaticPrompt (p, "Gap Type", 0, dialogTextHeight, programFont, 'c');
4146   dlg->linkage_type = PopupList (p, TRUE, ChangeGapType);
4147   InitEnumPopup (dlg->linkage_type, linkage_type_alist, NULL);
4148   SetEnumPopup (dlg->linkage_type, linkage_type_alist, 9);
4149   SetObjectExtra (dlg->linkage_type, dlg, NULL);
4150   StaticPrompt (p, "Linkage", 0, dialogTextHeight, programFont, 'c');
4151   dlg->linkage_linkage = PopupList (p, TRUE, ChangeGapType);
4152   SetObjectExtra(dlg->linkage_linkage, dlg, NULL);
4153   PopupItem (dlg->linkage_linkage, "Within Scaffolds");
4154   PopupItem (dlg->linkage_linkage, "Between Scaffolds");
4155   SetValue (dlg->linkage_linkage, 1);
4156   Disable (dlg->linkage_linkage);
4157   StaticPrompt (p, "Linkage Evidence", 0, dialogTextHeight, programFont, 'c');
4158   dlg->linkage_evidence = PopupList (p, TRUE, NULL);
4159   InitEnumPopup (dlg->linkage_evidence, linkage_evidence_alist, NULL);
4160   SetEnumPopup (dlg->linkage_evidence, linkage_evidence_alist, 0);
4161   ChangeGapType(dlg->linkage_linkage);
4162   return (DialoG) p;
4163 }
4164 
4165 
4166 typedef struct applylinkageform
4167 {
4168   FEATURE_FORM_BLOCK
4169 
4170   DialoG linkage_dlg;
4171 
4172 } ApplyLinkageFormData, PNTR ApplyLinkageFormPtr;
4173 
4174 
DoApplyLinkage(ButtoN b)4175 static void DoApplyLinkage(ButtoN b)
4176 {
4177   ApplyLinkageFormPtr frm;
4178   LinkageInfoPtr lp;
4179   SeqEntryPtr sep;
4180 
4181   frm = (ApplyLinkageFormPtr) GetObjectExtra(b);
4182   if (frm == NULL) {
4183     return;
4184   }
4185   sep = GetTopSeqEntryForEntityID(frm->input_entityID);
4186 
4187   lp = (LinkageInfoPtr) DialogToPointer(frm->linkage_dlg);
4188   if (lp != NULL) {
4189     VisitBioseqsInSep (sep, lp, AddLinkageInfoToBioseq);
4190   }
4191   lp = MemFree (lp);
4192   ObjMgrSetDirtyFlag (frm->input_entityID, TRUE);
4193   ObjMgrSendMsg (OM_MSG_UPDATE, frm->input_entityID, 0, 0);
4194 
4195   Remove (frm->form);
4196 }
4197 
4198 
ApplyLinkageInfo(IteM i)4199 static void ApplyLinkageInfo (IteM i)
4200 {
4201   BaseFormPtr         bfp;
4202   ApplyLinkageFormPtr frm;
4203   WindoW              w;
4204   GrouP               h, c;
4205   ButtoN              b;
4206 
4207 #ifdef WIN_MAC
4208   bfp = currentFormDataPtr;
4209 #else
4210   bfp = GetObjectExtra (i);
4211 #endif
4212   if (bfp == NULL) return;
4213 
4214   frm = (ApplyLinkageFormPtr) MemNew (sizeof (ApplyLinkageFormData));
4215   if (frm == NULL) return;
4216   frm->input_entityID = bfp->input_entityID;
4217 
4218   w = FixedWindow (-50, -33, -10, -10, "Apply Linkage Evidence to All Sequences", StdCloseWindowProc);
4219   SetObjectExtra (w, frm, StdCleanupFormProc);
4220   frm->form = (ForM) w;
4221   h = HiddenGroup (w, -1, 0, NULL);
4222   SetGroupSpacing (h, 10, 10);
4223   frm->linkage_dlg = LinkageInfoDialog(h);
4224 
4225   c = HiddenGroup (h, 4, 0, NULL);
4226   b = PushButton (c, "Accept", DoApplyLinkage);
4227   SetObjectExtra (b, frm, NULL);
4228   PushButton (c, "Cancel", StdCancelButtonProc);
4229 
4230   AlignObjects (ALIGN_CENTER, (HANDLE) frm->linkage_dlg,
4231                               (HANDLE) c,
4232                               NULL);
4233 
4234   RealizeWindow (w);
4235   Show (w);
4236   Update ();
4237 }
4238 
4239 
4240 typedef struct gapconversiondata
4241 {
4242   FEATURE_FORM_BLOCK
4243 
4244   GrouP  unknown_op;
4245   TexT   unknown_val_txt;
4246   GrouP  known_op;
4247   TexT   known_val_txt;
4248   ButtoN acceptBtn;
4249   DoC    explanation;
4250   ButtoN adjust_CDS_locations;
4251   ButtoN add_linkage;
4252   DialoG linkage_dlg;
4253 
4254 } GapConversionData, PNTR GapConversionPtr;
4255 
4256 static ParData faParFmt = {FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0};
4257 static ColData faColFmt = {0, 0, 80, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE};
4258 
SetConvertGapsAcceptAndText(GapConversionPtr gcp)4259 static void SetConvertGapsAcceptAndText (GapConversionPtr gcp)
4260 {
4261   Char             str[15];
4262   Int4 unknown_val, known_val;
4263   Int4 unknown_op, known_op;
4264   Char explanation[300];
4265 
4266   if (gcp == NULL || gcp->explanation == NULL) return;
4267   GetTitle (gcp->unknown_val_txt, str, sizeof (str));
4268   unknown_val = atoi (str);
4269   unknown_op = GetValue (gcp->unknown_op);
4270   GetTitle (gcp->known_val_txt, str, sizeof (str));
4271   known_val = atoi (str);
4272   known_op = GetValue (gcp->known_op);
4273 
4274   Reset (gcp->explanation);
4275   explanation [0] = 0;
4276 
4277   if (unknown_val < 0 || known_val < 0)
4278   {
4279     sprintf (explanation, "%s", "Negative values are not permitted.");
4280   	Disable (gcp->acceptBtn);
4281   }
4282   else if (known_val == unknown_val)
4283   {
4284     sprintf (explanation,
4285   	         "You must specify different values for known and unknown gap conversion sizes.");
4286   	Disable (gcp->acceptBtn);
4287   }
4288   else if (unknown_val == 0 && unknown_op == 1 && known_val == 0 && known_op == 1)
4289   {
4290     sprintf (explanation, "%s", "This combination will have no effect.");
4291     Disable (gcp->acceptBtn);
4292   }
4293   else if (unknown_val == 0 && unknown_op == 1 && (known_val == 0 || known_val == 1) && known_op == 2)
4294   {
4295     sprintf (explanation, "%s", "All sequences of Ns will be converted to gaps of known length.");
4296     Enable (gcp->acceptBtn);
4297   }
4298   else if ((unknown_val == 0 || unknown_val == 1) && unknown_op == 2 && known_val == 0 && known_op == 1)
4299   {
4300     sprintf (explanation, "%s", "All sequences of Ns will be converted to gaps of unknown length (size 100).");
4301     Enable (gcp->acceptBtn);
4302   }
4303   else if (unknown_val == 0 && unknown_op == 1)
4304   {
4305   	if (known_op == 1)
4306   	{
4307   	  sprintf (explanation,
4308   	           "All sequences of exactly %d Ns will be converted to gaps of known length.\n"
4309   	           "All other sequences of Ns will remain as Ns.", known_val);
4310    	  Enable (gcp->acceptBtn);
4311  	}
4312  	else
4313  	{
4314 	  sprintf (explanation,
4315   	             "All sequences of %d or more Ns will be converted to gaps of known length.\n"
4316   	             "All sequences of less than %d Ns will remain as Ns.", known_val, known_val);
4317   	  Enable (gcp->acceptBtn);
4318  	}
4319   }
4320   else if (known_val == 0 && known_op == 1)
4321   {
4322   	if (unknown_op == 1)
4323   	{
4324   	  sprintf (explanation,
4325   	           "All sequences of exactly %d Ns will be converted to gaps of unknown length (size 100).\n"
4326   	           "All other sequences of Ns will remain as Ns.", unknown_val);
4327   	  Enable (gcp->acceptBtn);
4328   	}
4329   	else if (unknown_op == 2)
4330   	{
4331   	  sprintf (explanation,
4332   	           "All sequences of %d or more Ns will be converted to gaps of unknown length.\n"
4333   	           "All sequences of less than %d Ns will remain as Ns.", unknown_val, unknown_val);
4334   	  Enable (gcp->acceptBtn);
4335   	}
4336   }
4337   else if (known_op == 1 && unknown_op == 1)
4338   {
4339   	sprintf (explanation,
4340   	         "All sequences of exactly %d Ns will be converted to gaps of known length.\n"
4341   	         "All sequences of exactly %d Ns will be converted to gaps of unknown length (size 100).\n"
4342   	         "All sequences of Ns with lengths other than %d or %d will remain as Ns.",
4343   	         known_val, unknown_val, known_val, unknown_val);
4344   	Enable (gcp->acceptBtn);
4345   }
4346   else if (known_op == 2 && unknown_op == 2)
4347   {
4348     /* handle cases where both operators are greater than/equal to */
4349   	if (known_val > unknown_val)
4350   	{
4351   	  if (unknown_val == 0 || unknown_val == 1)
4352   	  {
4353   	    sprintf (explanation,
4354   	             "All sequences of Ns with lengths >= 1 and <= %d will be converted to gaps of unknown length (size 100).\n"
4355   	             "All sequences of Ns with lengths >= %d will be converted to gaps of known length.\n",
4356   	             known_val -1, known_val);
4357   	  }
4358   	  else
4359   	  {
4360   	  	sprintf (explanation,
4361   	             "All sequences of Ns with lengths >= %d and <= %d will be converted to gaps of unknown length (size 100).\n"
4362   	             "All sequences of Ns with lengths >= %d will be converted to gaps of known length.\n"
4363   	             "All sequences of Ns with lengths <= %d will remain as Ns.",
4364   	             unknown_val, known_val -1, known_val, unknown_val - 1);
4365   	  }
4366   	}
4367   	else
4368   	{
4369   	  if (known_val == 0 || known_val == 1)
4370   	  {
4371   	    sprintf (explanation,
4372   	             "All sequences of Ns with lengths >= 1 and <= %d will be converted to gaps of known length.\n"
4373   	             "All sequences of Ns with lengths >= %d will be converted to gaps of unknown length (size 100).\n",
4374   	             unknown_val -1, unknown_val);
4375   	  }
4376   	  else
4377   	  {
4378   	  	sprintf (explanation,
4379   	             "All sequences of Ns with lengths >= %d and <= %d will be converted to gaps of known length.\n"
4380   	             "All sequences of Ns with lengths >= %d will be converted to gaps of unknown length (size 100).\n"
4381   	             "All sequences of Ns with lengths <= %d will remain as Ns.",
4382   	             known_val, unknown_val -1, unknown_val, known_val - 1);
4383   	  }
4384   	}
4385   }
4386   else if (known_val > unknown_val)
4387   {
4388   	if (known_op == 1)
4389   	{
4390   	  /* we know that unknown_op is 2 */
4391       if (unknown_val == 0 || unknown_val == 1)
4392   	  {
4393         sprintf (explanation,
4394   	           "All sequences of exactly %d Ns will be converted to gaps of known length.\n"
4395   	           "All sequences of Ns with lengths >= 1 and <= %d or lengths >= %d will be converted to gaps of unknown length (size 100).\n",
4396   	           known_val, known_val - 1, known_val + 1);
4397   	  }
4398   	  else
4399   	  {
4400         sprintf (explanation,
4401   	            "All sequences of exactly %d Ns will be converted to gaps of known length.\n"
4402   	             "All sequences of Ns with lengths >= %d and <= %d or lengths >= %d will be converted to gaps of unknown length (size 100).\n"
4403   	             "All sequences of Ns with lengths <= %d will remain as Ns.",
4404   	             known_val, unknown_val, known_val - 1, known_val + 1, unknown_val - 1);
4405   	  }
4406   	  Enable (gcp->acceptBtn);
4407   	}
4408   	else if (known_op == 2)
4409   	{
4410   	  /* we know that unknown_op is 1 */
4411   	  if (unknown_val == 1)
4412   	  {
4413   	  	sprintf (explanation,
4414   	           "All sequences of exactly 1 Ns will be converted to gaps of unknown length (size 100).\n"
4415   	           "All sequences with lengths >= %d will be converted to gaps of known length.\n"
4416   	           "All sequences of Ns with lengths >= 2 and <= %d will remain as Ns",
4417   	  	        known_val, known_val - 1);
4418   	  }
4419   	  else
4420   	  {
4421         sprintf (explanation,
4422   	           "All sequences of exactly %d Ns will be converted to gaps of unknown length (size 100).\n"
4423   	           "All sequences of Ns with lengths >= %d will be converted to gaps of known length.\n"
4424   	           "All sequences of Ns with lengths >= %d or lengths >= %d and <= %d will remain as Ns.  ",
4425   	           unknown_val, known_val, unknown_val - 1, unknown_val + 1, known_val - 1);
4426   	  }
4427   	  Enable (gcp->acceptBtn);
4428   	}
4429   }
4430   else
4431   {
4432   	/* unknown_val > known_val */
4433     if (known_op == 1)
4434     {
4435       /* we know that unknown_op is 2 */
4436   	  sprintf (explanation,
4437   	           "All sequences of exactly %d Ns will be converted to gaps of known length.\n"
4438   	           "All sequences of Ns with lengths >= %d will be converted to gaps of unknown length (size 100).\n"
4439   	           "All sequences of Ns with lengths <= %d or lengths >= %d and <= %d will remain as Ns.\n",
4440   	            known_val, unknown_val, known_val - 1, known_val + 1, unknown_val - 1);
4441     }
4442     else
4443     {
4444       /* we know that unknown_op is 1, known_op is 2 */
4445       if (known_val == 0 || known_val == 1)
4446       {
4447       	sprintf (explanation,
4448   	             "All sequences of exactly %d Ns will be converted to gaps of unknown length (size 100).\n"
4449   	             "All sequences of Ns with lengths >= 1 and <= %d or lengths >= %d will be converted to gaps of known length.\n",
4450       	         unknown_val, unknown_val - 1, unknown_val + 1);
4451       }
4452       else
4453       {
4454       	sprintf (explanation,
4455   	             "All sequences of exactly %d Ns will be converted to gaps of unknown length (size 100).\n"
4456   	             "All sequences of Ns with lengths >= %d and <= %d or lengths >= %d will be converted to gaps of known length.\n"
4457   	             "All sequences of Ns with lengths <= %d will remain as Ns.",
4458       	         unknown_val, known_val, unknown_val - 1, unknown_val + 1, known_val);
4459 
4460       }
4461     }
4462     Enable (gcp->acceptBtn);
4463   }
4464   AppendText (gcp->explanation, explanation, &faParFmt, &faColFmt, programFont);
4465   UpdateDocument (gcp->explanation, 0, 0);
4466   Update ();
4467 }
4468 
SetGapsConvertAcceptButtonAndTextGroup(GrouP g)4469 static void SetGapsConvertAcceptButtonAndTextGroup (GrouP g)
4470 {
4471   GapConversionPtr gcp;
4472 
4473   gcp = (GapConversionPtr) GetObjectExtra (g);
4474   SetConvertGapsAcceptAndText (gcp);
4475 }
4476 
SetGapsConvertAcceptButtonAndTextText(TexT nText)4477 static void SetGapsConvertAcceptButtonAndTextText (TexT nText)
4478 {
4479   GapConversionPtr gcp;
4480 
4481   gcp = (GapConversionPtr) GetObjectExtra (nText);
4482   SetConvertGapsAcceptAndText (gcp);
4483 }
4484 
ConvertGaps(ButtoN b)4485 static void ConvertGaps (ButtoN b)
4486 {
4487   GapConversionPtr gcp;
4488   SeqEntryPtr      sep;
4489   Int4             gap_sizes[2];
4490   Char             str[15];
4491   Int4             unknown_val, known_val;
4492   Int4             unknown_op, known_op;
4493   LinkageInfoPtr   lp = NULL;
4494 
4495   if (b == NULL) return;
4496   gcp = (GapConversionPtr) GetObjectExtra (b);
4497   if (gcp == NULL) return;
4498   sep = GetTopSeqEntryForEntityID (gcp->input_entityID);
4499   if (sep == NULL) return;
4500 
4501   GetTitle (gcp->unknown_val_txt, str, sizeof (str));
4502   unknown_val = atoi (str);
4503   unknown_op = GetValue (gcp->unknown_op);
4504   if (unknown_op == 1)
4505   {
4506   	gap_sizes [0] = unknown_val;
4507   }
4508   else
4509   {
4510     if (unknown_val == 0)
4511       unknown_val = 1;
4512   	gap_sizes[0] = 0 - unknown_val;
4513   }
4514   GetTitle (gcp->known_val_txt, str, sizeof (str));
4515   known_val = atoi (str);
4516   known_op = GetValue (gcp->known_op);
4517   if (known_op == 1)
4518   {
4519   	gap_sizes [1] = known_val;
4520   }
4521   else
4522   {
4523     if (known_val == 0)
4524       known_val = 1;
4525   	gap_sizes[1] = 0 - known_val;
4526   }
4527 
4528   if (GetStatus(gcp->add_linkage)) {
4529     lp = DialogToPointer(gcp->linkage_dlg);
4530   }
4531 
4532   Hide (gcp->form);
4533   ConvertNsToGapsWithSizeList (gcp->input_entityID, gap_sizes, GetStatus (gcp->adjust_CDS_locations), lp);
4534   lp = MemFree (lp);
4535 
4536   ObjMgrSetDirtyFlag (gcp->input_entityID, TRUE);
4537   ObjMgrSendMsg (OM_MSG_UPDATE, gcp->input_entityID, 0, 0);
4538   Remove (gcp->form);
4539 }
4540 
ListRawSequencesInAlignments(BioseqPtr bsp,Pointer userdata)4541 static void ListRawSequencesInAlignments (BioseqPtr bsp, Pointer userdata)
4542 {
4543   ValNodePtr PNTR raw_list;
4544   Char            id_str [128];
4545 
4546   if (bsp == NULL || bsp->repr != Seq_repr_raw || userdata == NULL)
4547   {
4548   	return;
4549   }
4550 
4551   if (!IsBioseqInAnyAlignment (bsp, bsp->idx.entityID))
4552   {
4553     return;
4554   }
4555 
4556   raw_list = (ValNodePtr PNTR) userdata;
4557   SeqIdWrite (SeqIdFindBest (bsp->id, SEQID_GENBANK), id_str, PRINTID_REPORT, sizeof (id_str) - 1);
4558   ValNodeAddPointer (raw_list, 0, StringSave (id_str));
4559 }
4560 
ContinueWithSequencesInAlignments(SeqEntryPtr sep)4561 static Boolean ContinueWithSequencesInAlignments (SeqEntryPtr sep)
4562 {
4563   ValNodePtr raw_in_aln = NULL;
4564   CharPtr    msg;
4565   MsgAnswer  ans;
4566 
4567   VisitBioseqsInSep (sep, &raw_in_aln, ListRawSequencesInAlignments);
4568   if (raw_in_aln != NULL)
4569   {
4570   	msg = CreateListMessage ("Sequence",
4571   	                         raw_in_aln->next == NULL
4572   	                              ? " is in an alignment.  The alignment will be automatically adjusted after conversion.  Do you want to continue?"
4573   	                              : " are in alignments.  The alignment will be automatically adjusted after conversion.  Do you want to continue?",
4574   	                              raw_in_aln);
4575   	raw_in_aln = ValNodeFreeData (raw_in_aln);
4576     ans = Message (MSG_YN, msg);
4577     msg = MemFree (msg);
4578     if (ans == ANS_NO)
4579     {
4580       return FALSE;
4581     }
4582   }
4583   return TRUE;
4584 }
4585 
ListDeltaSequences(BioseqPtr bsp,Pointer userdata)4586 static void ListDeltaSequences (BioseqPtr bsp, Pointer userdata)
4587 {
4588   ValNodePtr PNTR delta_list;
4589   Char            id_str [128];
4590 
4591   if (bsp == NULL || bsp->repr != Seq_repr_delta || userdata == NULL)
4592   {
4593   	return;
4594   }
4595 
4596   delta_list = (ValNodePtr PNTR) userdata;
4597   SeqIdWrite (SeqIdFindBest (bsp->id, SEQID_GENBANK), id_str, PRINTID_REPORT, sizeof (id_str) - 1);
4598   ValNodeAddPointer (delta_list, 0, StringSave (id_str));
4599 }
4600 
ContinueWithDeltaSequences(SeqEntryPtr sep)4601 static Boolean ContinueWithDeltaSequences (SeqEntryPtr sep)
4602 {
4603   ValNodePtr delta_list = NULL;
4604   CharPtr    msg;
4605   MsgAnswer  ans;
4606 
4607   VisitBioseqsInSep (sep, &delta_list, ListDeltaSequences);
4608   if (delta_list != NULL)
4609   {
4610   	msg = CreateListMessage ("Sequence",
4611   	                         delta_list->next == NULL
4612   	                              ? " is already a delta sequence and gaps will not be added.  Do you want to continue?"
4613   	                              : " are already delta sequences and gaps will not be added.  Do you want to continue?",
4614   	                              delta_list);
4615   	delta_list = ValNodeFreeData (delta_list);
4616     ans = Message (MSG_YN, msg);
4617     msg = MemFree (msg);
4618     if (ans == ANS_NO)
4619     {
4620       return FALSE;
4621     }
4622   }
4623   return TRUE;
4624 }
4625 
4626 
ChangeAddLinkage(ButtoN b)4627 static void ChangeAddLinkage(ButtoN b)
4628 {
4629   GapConversionPtr gcp;
4630 
4631   gcp = (GapConversionPtr) GetObjectExtra (b);
4632   if (gcp == NULL) {
4633     return;
4634   }
4635 
4636   if (GetStatus (gcp->add_linkage)) {
4637     Enable (gcp->linkage_dlg);
4638   } else {
4639     Disable (gcp->linkage_dlg);
4640   }
4641 }
4642 
4643 
RawSeqToDeltaSeqUnknownWithUnknownLengthGaps(IteM i)4644 static void RawSeqToDeltaSeqUnknownWithUnknownLengthGaps (IteM i)
4645 {
4646   BaseFormPtr      bfp;
4647   GapConversionPtr gcp;
4648   WindoW           w;
4649   GrouP            h, l, g, c;
4650   RecT             r;
4651   PrompT           p1, p2;
4652   SeqEntryPtr      sep;
4653 
4654 #ifdef WIN_MAC
4655   bfp = currentFormDataPtr;
4656 #else
4657   bfp = GetObjectExtra (i);
4658 #endif
4659   if (bfp == NULL) return;
4660 
4661   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
4662   if (!ContinueWithDeltaSequences (sep))
4663   {
4664     return;
4665   }
4666   if (!ContinueWithSequencesInAlignments (sep))
4667   {
4668     return;
4669   }
4670 
4671   gcp = (GapConversionPtr) MemNew (sizeof (GapConversionData));
4672   if (gcp == NULL) return;
4673 
4674   gcp->input_entityID = bfp->input_entityID;
4675   w = FixedWindow (-50, -33, -10, -10, "Convert Ns to Gaps", StdCloseWindowProc);
4676   SetObjectExtra (w, gcp, StdCleanupFormProc);
4677   gcp->form = (ForM) w;
4678   h = HiddenGroup (w, -1, 0, NULL);
4679   SetGroupSpacing (h, 10, 10);
4680   p1 = StaticPrompt (h, "Choose size of length of Ns to convert to gaps of unknown length", 0, dialogTextHeight, programFont, 'c');
4681   g = HiddenGroup (h, 2, 0, NULL);
4682   gcp->unknown_op = HiddenGroup (g, 0, 2, SetGapsConvertAcceptButtonAndTextGroup);
4683   SetObjectExtra (gcp->unknown_op, gcp, NULL);
4684   RadioButton (gcp->unknown_op, "=");
4685   RadioButton (gcp->unknown_op, ">=");
4686   SetValue (gcp->unknown_op, 1);
4687   gcp->unknown_val_txt = DialogText (g, "100", 14, SetGapsConvertAcceptButtonAndTextText);
4688   SetObjectExtra (gcp->unknown_val_txt, gcp, NULL);
4689   p2 = StaticPrompt (h, "Choose size of length of Ns to convert to gaps of known length", 0, dialogTextHeight, programFont, 'c');
4690   l = HiddenGroup (h, 2, 0, NULL);
4691   gcp->known_op = HiddenGroup (l, 0, 2, SetGapsConvertAcceptButtonAndTextGroup);
4692   SetObjectExtra (gcp->known_op, gcp, NULL);
4693   RadioButton (gcp->known_op, "=");
4694   RadioButton (gcp->known_op, ">=");
4695   SetValue (gcp->known_op, 2);
4696   gcp->known_val_txt = DialogText (l, "101", 14, SetGapsConvertAcceptButtonAndTextText);
4697   SetObjectExtra (gcp->known_val_txt, gcp, NULL);
4698 
4699   /* status text */
4700   gcp->explanation = DocumentPanel (h, stdCharWidth * 27, stdLineHeight * 8);
4701   ObjectRect (gcp->explanation, &r);
4702   InsetRect (&r, 4, 4);
4703   faColFmt.pixWidth = r.right - r.left;
4704 
4705   gcp->adjust_CDS_locations = CheckBox (h, "Adjust CDS locations for gaps", NULL);
4706   SetStatus (gcp->adjust_CDS_locations, TRUE);
4707 
4708   gcp->add_linkage = CheckBox (h, "Add linkage information to gaps", ChangeAddLinkage);
4709   SetObjectExtra (gcp->add_linkage, gcp, NULL);
4710 
4711   gcp->linkage_dlg = LinkageInfoDialog(h);
4712   Disable(gcp->linkage_dlg);
4713 
4714   c = HiddenGroup (h, 4, 0, NULL);
4715   gcp->acceptBtn = PushButton (c, "Accept", ConvertGaps);
4716   SetObjectExtra (gcp->acceptBtn, gcp, NULL);
4717   PushButton (c, "Cancel", StdCancelButtonProc);
4718 
4719   AlignObjects (ALIGN_CENTER, (HANDLE) p1,
4720                               (HANDLE) g,
4721                               (HANDLE) p2,
4722                               (HANDLE) l,
4723                               (HANDLE) gcp->explanation,
4724                               (HANDLE) gcp->adjust_CDS_locations,
4725                               (HANDLE) c,
4726                               NULL);
4727 
4728   SetConvertGapsAcceptAndText (gcp);
4729   RealizeWindow (w);
4730   Show (w);
4731   Update ();
4732 }
4733 
4734 static Uint2 deltaconversionedittypes [] =
4735 {
4736   TAGLIST_TEXT, TAGLIST_POPUP, TAGLIST_TEXT, TAGLIST_POPUP
4737 };
4738 
ENUM_ALIST(deltaconversionedit_alist)4739 ENUM_ALIST(deltaconversionedit_alist)
4740   {"Unknown length",  0},
4741   {"Known Length",    1},
4742 END_ENUM_ALIST
4743 
4744 ENUM_ALIST(deltaconversionedit_type_alist)
4745   {"Insert",  0},
4746   {"Replace",    1},
4747 END_ENUM_ALIST
4748 
4749 EnumFieldAssocPtr deltaconversionedit_alists [] = {
4750   NULL, deltaconversionedit_alist, NULL, deltaconversionedit_type_alist
4751 };
4752 
4753 static Uint2 deltaconversionedit_widths [] = {
4754   5, 5, 5, 5
4755 };
4756 
4757 typedef struct deltaconversion
4758 {
4759   FEATURE_FORM_BLOCK
4760 
4761   DialoG gap_locations;
4762   GrouP  coord_grp;
4763   ButtoN adjust_CDS_locations;
4764 
4765 } DeltaConversionData, PNTR DeltaConversionPtr;
4766 
4767 
4768 static SeqAlignPtr
AdjustOneAlignmentForOneBioseqBasedOnGapLocations(SeqAlignPtr salp_to_adjust,BioseqPtr bsp,ValNodePtr gaps,SeqAlignPtr gap_salp)4769 AdjustOneAlignmentForOneBioseqBasedOnGapLocations
4770 (SeqAlignPtr salp_to_adjust,
4771  BioseqPtr   bsp,
4772  ValNodePtr  gaps,
4773  SeqAlignPtr gap_salp)
4774 {
4775   Int4          aln_index;
4776   SeqIdPtr      sip;
4777   ValNodePtr    gap_vnp;
4778   GapLocInfoPtr glip;
4779   SeqLocPtr     slp;
4780   Int4          gap_start;
4781   Int4          cumulative_offset = 0;
4782   DenseSegPtr   dsp;
4783 
4784   if (salp_to_adjust == NULL || salp_to_adjust->segtype != SAS_DENSEG
4785       || bsp == NULL || gaps == NULL)
4786   {
4787     return salp_to_adjust;
4788   }
4789 
4790   dsp = (DenseSegPtr) salp_to_adjust->segs;
4791   if (dsp == NULL) {
4792      return salp_to_adjust;
4793   }
4794   sip = bsp->id;
4795   aln_index = 0;
4796   while (sip != NULL && aln_index == 0)
4797   {
4798     aln_index = SeqIdOrderInBioseqIdList (sip, dsp->ids);
4799     if (aln_index == 0)
4800     {
4801       sip = sip->next;
4802     }
4803   }
4804   if (aln_index == 0) {
4805      /* bioseq not in alignment */
4806      return salp_to_adjust;
4807   }
4808 
4809   for (gap_vnp = gaps; gap_vnp != NULL; gap_vnp = gap_vnp->next)
4810   {
4811     glip = (GapLocInfoPtr) gap_vnp->data.ptrvalue;
4812     if (glip == NULL || glip->replace)
4813     {
4814       continue;
4815     }
4816     gap_start = glip->start_pos;
4817     if (gap_salp != NULL)
4818     {
4819       gap_start = AlnMgr2MapSeqAlignToBioseq(gap_salp, gap_start, aln_index);
4820     }
4821     if (gap_start < 1)
4822     {
4823       continue;
4824     }
4825     gap_start += cumulative_offset;
4826     if (gap_start > bsp->length)
4827     {
4828       continue;
4829     }
4830     slp = SeqLocIntNew (gap_start, gap_start + glip->length - 1, Seq_strand_plus, sip);
4831     salp_to_adjust = SeqAlignInsertByLoc (slp, salp_to_adjust);
4832     cumulative_offset += glip->length;
4833   }
4834 
4835   return salp_to_adjust;
4836 }
4837 
4838 
ShiftAlignmentForGapLocations(SeqAnnotPtr sanp,ValNodePtr gaps)4839 static void ShiftAlignmentForGapLocations (SeqAnnotPtr sanp, ValNodePtr gaps)
4840 {
4841   SeqAlignPtr   salp;
4842   DenseSegPtr   dsp;
4843   Int4          alignment_position = 0, k;
4844   Int4          cumulative_offset = 0;
4845   BoolPtr       shift_this_row;
4846   Int4          seg_num = 0, shift_seg;
4847   ValNodePtr    gap_vnp;
4848   GapLocInfoPtr glip;
4849 
4850   if (sanp == NULL || sanp->data == NULL || sanp->type != 2 || gaps == NULL)
4851   {
4852     return;
4853   }
4854 
4855   salp = (SeqAlignPtr) sanp->data;
4856   if (salp->segtype != SAS_DENSEG || salp->segs == NULL)
4857   {
4858     return;
4859   }
4860 
4861   dsp = (DenseSegPtr) salp->segs;
4862 
4863   shift_this_row = (BoolPtr) MemNew (sizeof (Boolean) * dsp->dim);
4864 
4865   for (gap_vnp = gaps; gap_vnp != NULL; gap_vnp = gap_vnp->next)
4866   {
4867     glip = (GapLocInfoPtr) gap_vnp->data.ptrvalue;
4868     if (glip == NULL || glip->replace)
4869     {
4870       continue;
4871     }
4872     while (seg_num < dsp->numseg
4873            && alignment_position + dsp->lens [seg_num] < glip->start_pos + cumulative_offset)
4874 
4875     {
4876       alignment_position += dsp->lens [seg_num];
4877       seg_num++;
4878     }
4879 
4880     if (seg_num < dsp->numseg)
4881     {
4882       dsp->lens [seg_num] += glip->length;
4883       for (k = 0; k < dsp->dim; k++)
4884       {
4885         if (dsp->starts [seg_num * dsp->dim + k] == -1)
4886         {
4887           shift_this_row[k] = FALSE;
4888         }
4889         else
4890         {
4891           shift_this_row[k] = TRUE;
4892         }
4893       }
4894 
4895       /* shift the rows for which a gap was inserted */
4896       for (k = 0; k < dsp->dim; k++)
4897       {
4898         if (!shift_this_row[k])
4899         {
4900           continue;
4901         }
4902         /* shift start for minus strand rows for seg_num only */
4903         if (dsp->strands != NULL
4904             && dsp->strands [seg_num * dsp->dim + k] == Seq_strand_minus
4905             && dsp->starts [seg_num * dsp->dim + k] != -1)
4906         {
4907           dsp->starts [seg_num * dsp->dim + k] -= glip->length;
4908         }
4909         /* shift starts for rows after seg_num */
4910         for (shift_seg = seg_num + 1;
4911              shift_seg < dsp->numseg;
4912              shift_seg++)
4913         {
4914           if (dsp->starts [shift_seg * dsp->dim + k] != -1)
4915           {
4916             if (dsp->strands == NULL
4917                 || dsp->strands [shift_seg * dsp->dim + k] != Seq_strand_minus)
4918             {
4919               dsp->starts [shift_seg * dsp->dim + k] += glip->length;
4920             }
4921             else
4922             {
4923               dsp->starts [shift_seg * dsp->dim + k] -= glip->length;
4924             }
4925           }
4926         }
4927       }
4928     }
4929     cumulative_offset += glip->length;
4930   }
4931   shift_this_row = MemFree (shift_this_row);
4932 }
4933 
4934 static void
AdjustAlignmentsBasedOnGapLocations(ValNodePtr adjusted_bsp_list,ValNodePtr gaps,SeqAlignPtr salp,Uint2 entityID)4935 AdjustAlignmentsBasedOnGapLocations
4936 (ValNodePtr  adjusted_bsp_list,
4937  ValNodePtr  gaps,
4938  SeqAlignPtr salp,
4939  Uint2       entityID)
4940 {
4941   ValNodePtr  align_annot_list, annot_vnp, bsp_vnp;
4942   SeqAnnotPtr sanp, adjustment_sanp = NULL;
4943   BioseqPtr   bsp;
4944 
4945   for (bsp_vnp = adjusted_bsp_list; bsp_vnp != NULL; bsp_vnp = bsp_vnp->next)
4946   {
4947     bsp = (BioseqPtr)(bsp_vnp->data.ptrvalue);
4948     align_annot_list = FindAlignSeqAnnotsForBioseq (bsp);
4949     for (annot_vnp = align_annot_list;
4950          annot_vnp != NULL;
4951          annot_vnp = annot_vnp->next)
4952     {
4953       sanp = annot_vnp->data.ptrvalue;
4954       if (sanp != NULL && sanp->type == 2)
4955       {
4956         if (sanp->data == salp)
4957         {
4958           adjustment_sanp = sanp;
4959         }
4960         else
4961         {
4962           sanp->data = AdjustOneAlignmentForOneBioseqBasedOnGapLocations
4963                               (sanp->data, bsp, gaps, salp);
4964         }
4965       }
4966     }
4967     align_annot_list = ValNodeFree (align_annot_list);
4968   }
4969 
4970   if (adjustment_sanp != NULL)
4971   {
4972     ShiftAlignmentForGapLocations (adjustment_sanp, gaps);
4973   }
4974 
4975   CleanupAlignmentsAfterConversion (adjusted_bsp_list, entityID);
4976 }
4977 
4978 
4979 static void
ConvertRawBioseqToDelta(BioseqPtr bsp,ValNodePtr gaps,SeqAlignPtr salp,Int4 aln_row)4980 ConvertRawBioseqToDelta
4981 (BioseqPtr bsp,
4982  ValNodePtr gaps,
4983  SeqAlignPtr salp,
4984  Int4        aln_row)
4985 
4986 {
4987   CharPtr       bases;
4988   Int4          len;
4989   ValNodePtr    seq_ext;
4990   SeqLitPtr     slp;
4991   IntFuzzPtr    ifp;
4992   ValNodePtr    gap_vnp;
4993   GapLocInfoPtr glip;
4994   Int4          orig_seq_offset;
4995   Char          tmp_ch;
4996   Int4          gap_start;
4997   SeqEntryPtr   sep;
4998 
4999   if (bsp == NULL || bsp->repr != Seq_repr_raw || ISA_aa (bsp->mol)
5000       || gaps == NULL)
5001   {
5002     return;
5003   }
5004   if (salp != NULL && aln_row < 1)
5005   {
5006     return;
5007   }
5008 
5009   bases = GetSequenceByBsp (bsp);
5010   if (bases == NULL) return;
5011 
5012   seq_ext = NULL;
5013   len = 0;
5014   orig_seq_offset = 0;
5015 
5016   for (gap_vnp = gaps; gap_vnp != NULL; gap_vnp = gap_vnp->next)
5017   {
5018     glip = (GapLocInfoPtr) gap_vnp->data.ptrvalue;
5019     if (glip == NULL)
5020     {
5021       continue;
5022     }
5023     gap_start = glip->start_pos;
5024     /* remap for alignment coordinates if desired */
5025     if (salp != NULL)
5026     {
5027       gap_start = AlnMgr2MapSeqAlignToBioseq(salp, gap_start, aln_row);
5028     }
5029     if (gap_start < 1 || gap_start > bsp->length)
5030     {
5031       continue;
5032     }
5033 
5034     /* add data since last gap */
5035     if (gap_start - orig_seq_offset > 0) {
5036       slp = (SeqLitPtr) MemNew (sizeof (SeqLit));
5037       if (slp != NULL)
5038       {
5039         slp->length = gap_start - orig_seq_offset;
5040         ValNodeAddPointer (&(seq_ext), (Int2) 2, (Pointer) slp);
5041         slp->seq_data = (SeqDataPtr) BSNew (slp->length);
5042         slp->seq_data_type = Seq_code_iupacna;
5043         tmp_ch = bases [gap_start];
5044         bases [gap_start] = 0;
5045         AddBasesToByteStore ((ByteStorePtr) slp->seq_data, bases + orig_seq_offset);
5046         bases [gap_start] = tmp_ch;
5047         len += slp->length;
5048         orig_seq_offset += slp->length;
5049       }
5050     }
5051 
5052     /* add gap */
5053     slp = (SeqLitPtr) MemNew (sizeof (SeqLit));
5054     if (slp != NULL)
5055     {
5056       ValNodeAddPointer ((ValNodePtr PNTR) &(seq_ext), (Int2) 2, (Pointer) slp);
5057       if (glip->is_known)
5058       {
5059         slp->length = glip->length;
5060       }
5061       else
5062       {
5063         ifp = IntFuzzNew ();
5064         ifp->choice = 4;
5065         slp->fuzz = ifp;
5066         slp->length = 100;
5067       }
5068       len += slp->length;
5069     }
5070     if (glip->replace)
5071     {
5072       orig_seq_offset += glip->length;
5073     }
5074   }
5075 
5076   /* add remaining data after last gap to end */
5077   if (bsp->length - orig_seq_offset > 0) {
5078     slp = (SeqLitPtr) MemNew (sizeof (SeqLit));
5079     if (slp != NULL)
5080     {
5081       slp->length = bsp->length - orig_seq_offset;
5082       ValNodeAddPointer (&(seq_ext), (Int2) 2, (Pointer) slp);
5083       slp->seq_data = (SeqDataPtr) BSNew (slp->length);
5084       slp->seq_data_type = Seq_code_iupacna;
5085       AddBasesToByteStore ((ByteStorePtr) slp->seq_data, bases + orig_seq_offset);
5086       len += slp->length;
5087     }
5088   }
5089 
5090   MemFree (bases);
5091 
5092   bsp->seq_data = SeqDataFree (bsp->seq_data, bsp->seq_data_type);
5093   bsp->seq_data_type = 0;
5094   bsp->repr = Seq_repr_delta;
5095   bsp->seq_ext_type = 4;
5096   bsp->seq_ext = seq_ext;
5097   bsp->length = len;
5098 
5099   BioseqPack (bsp);
5100 
5101   /* now adjust features for insertion */
5102   orig_seq_offset = 0;
5103   for (gap_vnp = gaps; gap_vnp != NULL; gap_vnp = gap_vnp->next)
5104   {
5105     glip = (GapLocInfoPtr) gap_vnp->data.ptrvalue;
5106     if (glip == NULL)
5107     {
5108       continue;
5109     }
5110     gap_start = glip->start_pos;
5111     /* remap for alignment coordinates if desired */
5112     if (salp != NULL)
5113     {
5114       gap_start = AlnMgr2MapSeqAlignToBioseq(salp, gap_start, aln_row);
5115     }
5116     if (gap_start < 1 || gap_start > bsp->length)
5117     {
5118       continue;
5119     }
5120     if (!glip->replace) {
5121       AdjustFeaturesForInsertion (bsp, bsp->id,
5122                                 gap_start + orig_seq_offset,
5123                                 glip->length,
5124                                 FALSE);
5125     } else if (glip->length != 100 && !glip->is_known) {
5126       AdjustFeaturesForInsertion (bsp, bsp->id, gap_start + orig_seq_offset,
5127                                   100 - glip->length,
5128                                   FALSE);
5129     }
5130     orig_seq_offset += glip->length;
5131   }
5132 
5133   sep = GetTopSeqEntryForEntityID (bsp->idx.entityID);
5134 
5135   VisitFeaturesInSep (sep, (Pointer) Sequin_GlobalAlign2Seq, AdjustCDSLocationsForUnknownGapsCallback);
5136 
5137 }
5138 
5139 typedef struct converttodelta
5140 {
5141   ValNodePtr  location_list;
5142   ValNodePtr  affected_bioseq_list;
5143   SeqAlignPtr salp;
5144 } ConvertToDeltaData, PNTR ConvertToDeltaPtr;
5145 
ConvertBioseqToDeltaWithSequenceGapList(BioseqPtr bsp,Pointer userdata)5146 static void ConvertBioseqToDeltaWithSequenceGapList (BioseqPtr bsp, Pointer userdata)
5147 {
5148   ConvertToDeltaPtr ctdp;
5149 
5150   if (bsp == NULL || bsp->id == NULL
5151       || bsp->repr != Seq_repr_raw || ISA_aa (bsp->mol)
5152       || userdata == NULL)
5153   {
5154     return;
5155   }
5156   ctdp = (ConvertToDeltaPtr) userdata;
5157   if (ctdp->location_list == NULL)
5158   {
5159     return;
5160   }
5161   ValNodeAddPointer (&(ctdp->affected_bioseq_list), 0, bsp);
5162   ConvertRawBioseqToDelta (bsp, ctdp->location_list, NULL, -1);
5163 }
5164 
ConvertBioseqToDeltaWithAlignmentGapList(BioseqPtr bsp,Pointer userdata)5165 static void ConvertBioseqToDeltaWithAlignmentGapList (BioseqPtr bsp, Pointer userdata)
5166 {
5167   Int4              aln_row = -1;
5168   SeqIdPtr          sip, sip_next;
5169   SeqAlignPtr       salp;
5170   ConvertToDeltaPtr ctdp;
5171   ValNodePtr        annot_list;
5172   SeqAnnotPtr       sanp;
5173 
5174   if (bsp == NULL || bsp->id == NULL
5175       || bsp->repr != Seq_repr_raw || ISA_aa (bsp->mol)
5176       || userdata == NULL)
5177   {
5178     return;
5179   }
5180   ctdp = (ConvertToDeltaPtr) userdata;
5181   if (ctdp->location_list == NULL)
5182   {
5183     return;
5184   }
5185 
5186   annot_list = FindAlignSeqAnnotsForBioseq (bsp);
5187   if (annot_list == NULL || annot_list->data.ptrvalue == NULL)
5188   {
5189     return;
5190   }
5191   sanp = (SeqAnnotPtr) annot_list->data.ptrvalue;
5192   if (sanp->type != 2 || sanp->data == NULL)
5193   {
5194     return;
5195   }
5196 
5197   salp = sanp->data;
5198   ctdp->salp = salp;
5199 
5200   /* Make sure alignment is indexed.
5201    */
5202   AlnMgr2IndexSeqAlignEx(salp, FALSE);
5203 
5204   sip = bsp->id;
5205 
5206   while (sip != NULL && aln_row == -1)
5207   {
5208     sip_next = sip->next;
5209     sip->next = NULL;
5210     aln_row = AlnMgr2GetFirstNForSip (salp, sip);
5211     sip->next = sip_next;
5212     sip = sip_next;
5213   }
5214 
5215   ValNodeAddPointer (&(ctdp->affected_bioseq_list), 0, bsp);
5216   ConvertRawBioseqToDelta (bsp, ctdp->location_list, salp, aln_row);
5217 }
5218 
5219 
5220 static CharPtr gapTypeStrings [] = {
5221   "unknown",
5222   "within scaffold",
5223   "within scaffold",
5224   "between scaffolds",
5225   "short_arm",
5226   "heterochromatin",
5227   "centromere",
5228   "telomere",
5229   "repeat within scaffold",
5230   "repeat between scaffolds",
5231   "between scaffolds",
5232   "within scaffold",
5233   "other",
5234   NULL
5235 };
5236 
5237 static Int4 gapTypeValues [] = {
5238   0,
5239   1,
5240   2,
5241   2,
5242   3,
5243   4,
5244   5,
5245   6,
5246   7,
5247   7,
5248   8,
5249   9,
5250   255
5251 };
5252 
5253 static CharPtr linkEvStrings [] = {
5254   "paired-ends",
5255   "align genus",
5256   "align xgenus",
5257   "align trnscpt",
5258   "within clone",
5259   "clone contig",
5260   "map",
5261   "strobe",
5262   "unspecified",
5263   "pcr",
5264   "other",
5265   NULL
5266 };
5267 
5268 static Int4 linkEvValues [] = {
5269   0,
5270   1,
5271   2,
5272   3,
5273   4,
5274   5,
5275   6,
5276   7,
5277   8,
5278   9,
5279   255
5280 };
5281 
ConvertRawToDeltaWithGapFeatures(IteM i)5282 static void ConvertRawToDeltaWithGapFeatures (IteM i)
5283 
5284 {
5285   BaseFormPtr  bfp;
5286   SeqEntryPtr  sep;
5287 
5288 #ifdef WIN_MAC
5289   bfp = currentFormDataPtr;
5290 #else
5291   bfp = GetObjectExtra (i);
5292 #endif
5293   if (bfp == NULL) return;
5294 
5295   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
5296   if (sep == NULL) return;
5297 
5298   VisitBioseqsInSep (sep, Sequin_GlobalAlign2Seq, BioseqToDeltaByGapFeat);
5299 
5300   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
5301 
5302   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
5303   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
5304 }
5305 
5306 
5307 
5308 /* Start of SQD-1123 */
5309 
ValidateAssemblyGapFeat(SeqFeatPtr sfp,BioseqPtr bsp)5310 static Boolean ValidateAssemblyGapFeat (SeqFeatPtr sfp, BioseqPtr bsp)
5311 
5312 {
5313   Char       ch;
5314   int        i;
5315   size_t     len;
5316   Boolean    rsult = FALSE;
5317   CharPtr    seq;
5318   SeqIntPtr  sintp;
5319   SeqLocPtr  slp;
5320 
5321   if (sfp == NULL || sfp->location == NULL || bsp == NULL) return FALSE;
5322 
5323   slp = (SeqLocPtr) AsnIoMemCopy ((Pointer) sfp->location, (AsnReadFunc) SeqLocAsnRead, (AsnWriteFunc) SeqLocAsnWrite);
5324   if (slp == NULL) return FALSE;
5325 
5326   if (slp->choice == SEQLOC_INT) {
5327     sintp = (SeqIntPtr) slp->data.ptrvalue;
5328     if (sintp != NULL && sintp->from > 0 && sintp->to < bsp->length - 1) {
5329       (sintp->from)--;
5330       (sintp->to)++;
5331       seq = GetSequenceByLocation (slp);
5332       if (seq != NULL) {
5333         len = StringLen (seq);
5334         if (len > 0 && len == SeqLocLen (slp)) {
5335           ch = seq [0];
5336           if (IS_ALPHA (ch) && ch != 'N') {
5337             ch = seq [len - 1];
5338             if (IS_ALPHA (ch) && ch != 'N') {
5339               rsult = TRUE;
5340               for (i = 1; i < len - 1; i++) {
5341                 ch = seq [i];
5342                 if (ch != 'N') {
5343                   rsult = FALSE;
5344                 }
5345               }
5346             }
5347           }
5348         }
5349       }
5350       MemFree (seq);
5351     }
5352     SeqLocFree (slp);
5353   }
5354 
5355   return rsult;
5356 }
5357 
5358 static CharPtr gapTypeVals [] = {
5359   "unknown",
5360   "within scaffold",
5361   "between scaffolds",
5362   "short_arm",
5363   "heterochromatin",
5364   "centromere",
5365   "telomere",
5366   "repeat within scaffold",
5367   "between scaffolds",
5368   "within scaffold",
5369   "other",
5370   NULL
5371 };
5372 
5373 static CharPtr linkEvVals [] = {
5374   "paired-ends",
5375   "align genus",
5376   "align xgenus",
5377   "align trnscpt",
5378   "within clone",
5379   "clone contig",
5380   "map",
5381   "strobe",
5382   "unspecified",
5383   "pcr",
5384   "other",
5385   NULL
5386 };
5387 
InstantiateAssemblyGapFeats(BioseqPtr bsp)5388 static void InstantiateAssemblyGapFeats (BioseqPtr bsp)
5389 
5390 {
5391   Char                buf [128];
5392   Int4                currpos = 0, lastpos, linktype, type;
5393   ValNodePtr          evidvnp, vnp;
5394   Boolean             gap_is_linked;
5395   ImpFeatPtr          ifp;
5396   LinkageEvidencePtr  lep;
5397   SeqLitPtr           litp;
5398   SeqFeatPtr          sfp;
5399   SeqGapPtr           sgp;
5400   SeqIdPtr            sip;
5401   SeqLocPtr           slp;
5402 
5403   if (bsp == NULL || bsp->repr != Seq_repr_delta) return;
5404 
5405   sip = SeqIdFindBest (bsp->id, 0);
5406   if (sip == NULL) return;
5407 
5408   for (vnp = (ValNodePtr)(bsp->seq_ext); vnp != NULL; vnp = vnp->next) {
5409     if (vnp->choice == 1) {
5410       slp = (SeqLocPtr) vnp->data.ptrvalue;
5411       if (slp == NULL) continue;
5412       currpos += SeqLocLen (slp);
5413     }
5414     if (vnp->choice == 2) {
5415       litp = (SeqLitPtr) vnp->data.ptrvalue;
5416       if (litp == NULL) continue;
5417       lastpos = currpos;
5418       currpos += litp->length;
5419 
5420       if (litp->length == 0 ) continue;
5421 
5422       if (litp->seq_data == NULL) {
5423         ifp = ImpFeatNew ();
5424         if (ifp == NULL) continue;
5425         ifp->key = StringSave ("assembly_gap");
5426         sfp = CreateNewFeatureOnBioseq (bsp, SEQFEAT_IMP, NULL);
5427         if (sfp == NULL) continue;
5428         sfp->data.value.ptrvalue = (Pointer) ifp;
5429         sfp->excpt = TRUE;
5430         sfp->location = AddIntervalToLocation (NULL, sip, lastpos, currpos - 1, FALSE, FALSE);
5431         sprintf (buf, "%ld", (long) litp->length);
5432         AddQualifierToFeature (sfp, "estimated_length", buf);
5433         AddQualifierToFeature (sfp, "gap_type", "unknown");
5434         continue;
5435       }
5436 
5437       if (litp->seq_data_type != Seq_code_gap) continue;
5438       sgp = (SeqGapPtr) litp->seq_data;
5439       if (sgp == NULL) continue;
5440 
5441       ifp = ImpFeatNew ();
5442       if (ifp == NULL) continue;
5443       ifp->key = StringSave ("assembly_gap");
5444 
5445       sfp = CreateNewFeatureOnBioseq (bsp, SEQFEAT_IMP, NULL);
5446       if (sfp == NULL) continue;
5447       sfp->data.value.ptrvalue = (Pointer) ifp;
5448 
5449       sfp->excpt = TRUE;
5450 
5451       sfp->location = AddIntervalToLocation (NULL, sip, lastpos, currpos - 1, FALSE, FALSE);
5452 
5453       gap_is_linked = FALSE;
5454       if (sgp->linkage == 1 || sgp->linkage_evidence != NULL) {
5455         gap_is_linked = TRUE;
5456       }
5457 
5458       sprintf (buf, "%ld", (long) litp->length);
5459       AddQualifierToFeature (sfp, "estimated_length", buf);
5460 
5461       type = sgp->type;
5462       if (type == 2) {
5463         AddQualifierToFeature (sfp, "gap_type",  gap_is_linked ? "within scaffold" : "between scaffolds");
5464       } else if (type == 7) {
5465         AddQualifierToFeature (sfp, "gap_type",  gap_is_linked ? "repeat within scaffold" : "repeat between scaffolds");
5466       } else if (type >= 1 && type <= 9) {
5467         AddQualifierToFeature (sfp, "gap_type", gapTypeVals [type]);
5468       } else if (sgp->type == 255) {
5469         AddQualifierToFeature (sfp, "gap_type", "other");
5470       }
5471 
5472       for (evidvnp = sgp->linkage_evidence; evidvnp; evidvnp = evidvnp->next) {
5473         lep = (LinkageEvidencePtr) evidvnp->data.ptrvalue;
5474         if (lep == NULL) continue;
5475         linktype = lep->type;
5476         if (linktype >= 0 && linktype <= 9) {
5477           AddQualifierToFeature (sfp, "linkage_evidence", linkEvVals [linktype]);
5478         } else if (linktype == 255) {
5479           AddQualifierToFeature (sfp, "linkage_evidence", "other");
5480         }
5481       }
5482     }
5483   }
5484 }
5485 
5486 
ConvertAndMergeAssemblyGapFeatures(IteM i)5487 static void ConvertAndMergeAssemblyGapFeatures (IteM i)
5488 
5489 {
5490   BaseFormPtr  bfp;
5491   SeqEntryPtr  sep;
5492 
5493 #ifdef WIN_MAC
5494   bfp = currentFormDataPtr;
5495 #else
5496   bfp = GetObjectExtra (i);
5497 #endif
5498   if (bfp == NULL) return;
5499 
5500   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
5501   if (sep == NULL) return;
5502 
5503   VisitBioseqsInSep (sep, NULL, BioseqToDeltaMergeGapFeat);
5504 
5505   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
5506 
5507   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
5508   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
5509 }
5510 
5511 /* End of SQD-1123 */
5512 
5513 
5514 
SortGapLocations(VoidPtr ptr1,VoidPtr ptr2)5515 static int LIBCALLBACK SortGapLocations (VoidPtr ptr1, VoidPtr ptr2)
5516 
5517 {
5518   ValNodePtr    vnp1, vnp2;
5519   GapLocInfoPtr glip1, glip2;
5520 
5521   if (ptr1 != NULL && ptr2 != NULL) {
5522     vnp1 = *((ValNodePtr PNTR) ptr1);
5523     vnp2 = *((ValNodePtr PNTR) ptr2);
5524     if (vnp1 != NULL && vnp2 != NULL) {
5525       glip1 = (GapLocInfoPtr) vnp1->data.ptrvalue;
5526       glip2 = (GapLocInfoPtr) vnp2->data.ptrvalue;
5527       if (glip1 != NULL && glip2 != NULL) {
5528         if (glip1->start_pos < glip2->start_pos)
5529         {
5530           return -1;
5531         }
5532         else if (glip1->start_pos > glip2->start_pos)
5533         {
5534           return 1;
5535         }
5536         else if (glip1->length < glip2->length)
5537         {
5538           return -1;
5539         }
5540         else if (glip1->length > glip2->length)
5541         {
5542           return 1;
5543         }
5544         else
5545         {
5546           return 0;
5547         }
5548       }
5549     }
5550   }
5551   return 0;
5552 }
5553 
DeltaLocToData(DialoG d)5554 static Pointer DeltaLocToData (DialoG d)
5555 {
5556   TagListPtr    tlp;
5557   ValNodePtr    result_list = NULL, vnp;
5558   CharPtr       str;
5559   Int4          start_pos, len;
5560   Boolean       is_known, replace;
5561   GapLocInfoPtr glip;
5562 
5563   tlp = (TagListPtr) GetObjectExtra (d);
5564 
5565   if (tlp == NULL) return NULL;
5566 
5567   for (vnp = tlp->vnp;
5568        vnp != NULL;
5569        vnp = vnp->next)
5570   {
5571     str = ExtractTagListColumn ((CharPtr) vnp->data.ptrvalue, 0);
5572     if (StringHasNoText (str))
5573     {
5574       str = MemFree (str);
5575     }
5576     else
5577     {
5578       start_pos = atoi (str) - 1;
5579       str = MemFree (str);
5580       if (start_pos > 0)
5581       {
5582         str = ExtractTagListColumn ((CharPtr) vnp->data.ptrvalue, 3);
5583         if (StringICmp (str, "1") == 0)
5584         {
5585           replace = TRUE;
5586         }
5587         else
5588         {
5589           replace = FALSE;
5590         }
5591         str = MemFree (str);
5592 
5593         str = ExtractTagListColumn ((CharPtr) vnp->data.ptrvalue, 1);
5594         if (StringICmp (str, "1") == 0)
5595         {
5596           str = MemFree (str);
5597           is_known = TRUE;
5598           len = -1;
5599           str = ExtractTagListColumn ((CharPtr) vnp->data.ptrvalue, 2);
5600           if (!StringHasNoText (str))
5601           {
5602             len = atoi (str);
5603           }
5604           str = MemFree (str);
5605           if (len < 1)
5606           {
5607             Message (MSG_ERROR, "Must supply a length greater than zero for gaps of known length!");
5608             result_list = ValNodeFreeData (result_list);
5609             return NULL;
5610           }
5611         }
5612         else
5613         {
5614           str = MemFree (str);
5615           is_known = FALSE;
5616           if (replace)
5617           {
5618             str = ExtractTagListColumn ((CharPtr) vnp->data.ptrvalue, 2);
5619             if (StringHasNoText (str))
5620             {
5621               len = 100;
5622             }
5623             else
5624             {
5625               len = atoi (str);
5626               if (len < 1)
5627               {
5628                 len = 100;
5629               }
5630             }
5631             str = MemFree (str);
5632           }
5633           else
5634           {
5635             len = 100;
5636           }
5637         }
5638 
5639         glip = (GapLocInfoPtr) MemNew (sizeof (GapLocInfoData));
5640         if (glip != NULL)
5641         {
5642           glip->start_pos = start_pos;
5643           glip->is_known = is_known;
5644           glip->length = len;
5645           glip->replace = replace;
5646           ValNodeAddPointer (&result_list, 0, glip);
5647         }
5648       }
5649     }
5650   }
5651 
5652   result_list = ValNodeSort (result_list, SortGapLocations);
5653   return result_list;
5654 }
5655 
DoConvertRawToDeltaWithGapLocations(ButtoN b)5656 static void DoConvertRawToDeltaWithGapLocations (ButtoN b)
5657 {
5658   DeltaConversionPtr dcp;
5659   SeqEntryPtr        sep;
5660   ConvertToDeltaData ctdd;
5661 
5662   dcp = (DeltaConversionPtr) GetObjectExtra (b);
5663   if (dcp == NULL)
5664   {
5665     return;
5666   }
5667 
5668   sep = GetTopSeqEntryForEntityID (dcp->input_entityID);
5669   if (sep == NULL)
5670   {
5671     return;
5672   }
5673 
5674   ctdd.location_list = DialogToPointer (dcp->gap_locations);
5675   if (ctdd.location_list == NULL)
5676   {
5677     Message (MSG_ERROR, "Must supply valid gap locations!");
5678     return;
5679   }
5680   ctdd.affected_bioseq_list = NULL;
5681   ctdd.salp = NULL;
5682 
5683   Hide (dcp->form);
5684   WatchCursor ();
5685   Update ();
5686   if (dcp->coord_grp == NULL || GetValue (dcp->coord_grp) == 1)
5687   {
5688     VisitBioseqsInSep (sep, &ctdd, ConvertBioseqToDeltaWithSequenceGapList);
5689   }
5690   else
5691   {
5692     VisitBioseqsInSep (sep, &ctdd, ConvertBioseqToDeltaWithAlignmentGapList);
5693   }
5694 
5695   AdjustAlignmentsBasedOnGapLocations (ctdd.affected_bioseq_list,
5696                                        ctdd.location_list, ctdd.salp,
5697                                        dcp->input_entityID);
5698 
5699   ctdd.affected_bioseq_list = ValNodeFree (ctdd.affected_bioseq_list);
5700   ctdd.location_list = ValNodeFreeData (ctdd.location_list);
5701 
5702   if (GetStatus (dcp->adjust_CDS_locations))
5703   {
5704     VisitFeaturesInSep (sep, (Pointer)Sequin_GlobalAlign2Seq, AdjustCDSLocationsForUnknownGapsCallback);
5705     DeleteMarkedObjects (dcp->input_entityID, 0, NULL);
5706   }
5707 
5708   ObjMgrSetDirtyFlag (dcp->input_entityID, TRUE);
5709   ObjMgrSendMsg (OM_MSG_UPDATE, dcp->input_entityID, 0, 0);
5710   Remove (dcp->form);
5711   ArrowCursor ();
5712   Update ();
5713 }
5714 
5715 extern DialoG CreateTagListDialogEx (GrouP h, Uint2 rows, Uint2 cols,
5716                                      Int2 spacing, Uint2Ptr types,
5717                                      Uint2Ptr textWidths, EnumFieldAssocPtr PNTR alists,
5718                                      Boolean useBar, Boolean noExtend,
5719                                      ToDialogFunc tofunc, FromDialogFunc fromfunc);
5720 
ConvertRawToDeltaWithGapLocations(IteM i)5721 static void ConvertRawToDeltaWithGapLocations (IteM i)
5722 {
5723   BaseFormPtr        bfp;
5724   DeltaConversionPtr dcp;
5725   WindoW             w;
5726   GrouP              h, p, c;
5727   ButtoN             b;
5728   PrompT             p1, p2, p3;
5729   SeqEntryPtr        sep;
5730   RecT               r1, r2;
5731   TagListPtr         tlp;
5732 
5733 #ifdef WIN_MAC
5734   bfp = currentFormDataPtr;
5735 #else
5736   bfp = GetObjectExtra (i);
5737 #endif
5738   if (bfp == NULL) return;
5739 
5740   dcp = (DeltaConversionPtr) MemNew (sizeof (DeltaConversionData));
5741   if (dcp == NULL) return;
5742 
5743   dcp->input_entityID = bfp->input_entityID;
5744   sep = GetTopSeqEntryForEntityID (dcp->input_entityID);
5745   if (sep == NULL)
5746   {
5747     return;
5748   }
5749 
5750   if (!ContinueWithDeltaSequences (sep))
5751   {
5752     return;
5753   }
5754   if (!ContinueWithSequencesInAlignments (sep))
5755   {
5756     return;
5757   }
5758 
5759   w = FixedWindow (-50, -33, -10, -10, "Convert Raw Sequence to Delta Sequence", StdCloseWindowProc);
5760   SetObjectExtra (w, dcp, StdCleanupFormProc);
5761   dcp->form = (ForM) w;
5762   h = HiddenGroup (w, -1, 0, NULL);
5763   SetGroupSpacing (h, 10, 10);
5764 
5765   p = HiddenGroup (h, 3, 0, NULL);
5766   p1 = StaticPrompt (p, "Start", 0, dialogTextHeight, programFont, 'c');
5767   p2 = StaticPrompt (p, "Type", 0, dialogTextHeight, programFont, 'c');
5768   p3 = StaticPrompt (p, "Length", 0, dialogTextHeight, programFont, 'c');
5769   dcp->gap_locations = CreateTagListDialogEx (h, 4, 4, 2,
5770                                               deltaconversionedittypes,
5771                                               deltaconversionedit_widths,
5772                                               deltaconversionedit_alists,
5773                                               TRUE, FALSE, NULL, DeltaLocToData);
5774   dcp->coord_grp = NormalGroup (h, 2, 0, "Coordinates", programFont, NULL);
5775   RadioButton (dcp->coord_grp, "Sequence");
5776   RadioButton (dcp->coord_grp, "Alignment");
5777   SetValue (dcp->coord_grp, 1);
5778   if (!SeqEntryHasAligns (dcp->input_entityID, sep))
5779   {
5780     Disable (dcp->coord_grp);
5781   }
5782 
5783   dcp->adjust_CDS_locations = CheckBox (h, "Adjust CDS locations for gaps", NULL);
5784   SetStatus (dcp->adjust_CDS_locations, TRUE);
5785 
5786   c = HiddenGroup (h, 2, 0, NULL);
5787   b = PushButton (c, "Accept", DoConvertRawToDeltaWithGapLocations);
5788   SetObjectExtra (b, dcp, NULL);
5789   PushButton (c, "Cancel", StdCancelButtonProc);
5790 
5791   AlignObjects (ALIGN_CENTER, (HANDLE) dcp->gap_locations,
5792                               (HANDLE) dcp->coord_grp,
5793                               (HANDLE) dcp->adjust_CDS_locations,
5794                               (HANDLE) c,
5795                               NULL);
5796 
5797   tlp = GetObjectExtra (dcp->gap_locations);
5798   if (tlp != NULL)
5799   {
5800     ObjectRect (tlp->control [0], &r1);
5801     ObjectRect (p1, &r2);
5802     r2.left = r1.left;
5803     r2.right = r1.right;
5804     SetPosition (p1, &r2);
5805 
5806     ObjectRect (tlp->control [1], &r1);
5807     ObjectRect (p2, &r2);
5808     r2.left = r1.left;
5809     r2.right = r1.right;
5810     SetPosition (p2, &r2);
5811 
5812     ObjectRect (tlp->control [2], &r1);
5813     ObjectRect (p3, &r2);
5814     r2.left = r1.left;
5815     r2.right = r1.right;
5816     SetPosition (p3, &r2);
5817   }
5818   RealizeWindow (w);
5819 
5820   Show (w);
5821   Update ();
5822 }
5823 
5824 
5825 typedef struct xrefgenedata {
5826   GeneRefPtr  grp;
5827   SeqLocPtr   slp;
5828   Boolean     pseudo;
5829 } XrefGeneData, PNTR XrefGenePtr;
5830 
XrefToGeneCallback(GatherContextPtr gcp)5831 static Boolean XrefToGeneCallback (GatherContextPtr gcp)
5832 
5833 {
5834   GeneRefPtr           grp;
5835   SeqFeatXrefPtr PNTR  last;
5836   SeqFeatXrefPtr       next;
5837   SeqFeatPtr           sfp;
5838   ValNodePtr PNTR      vnpp;
5839   XrefGenePtr          xgp;
5840   SeqFeatXrefPtr       xref;
5841   BioseqPtr            bsp;
5842   Boolean              partial5, partial3;
5843 
5844   if (gcp->thistype != OBJ_SEQFEAT) return TRUE;
5845   vnpp = (ValNodePtr PNTR) gcp->userdata;
5846   if (vnpp == NULL) return TRUE;
5847   sfp = (SeqFeatPtr) gcp->thisitem;
5848   if (sfp == NULL || sfp->location == NULL) return TRUE;
5849   if (sfp->xref == NULL) return TRUE;
5850   grp = NULL;
5851   last = (SeqFeatXrefPtr PNTR) &(sfp->xref);
5852   xref = sfp->xref;
5853   while (xref != NULL) {
5854     next = xref->next;
5855     if (xref->data.choice == SEQFEAT_GENE) {
5856       *last = next;
5857       xref->next = NULL;
5858       grp = (GeneRefPtr) xref->data.value.ptrvalue;
5859       xref->data.value.ptrvalue = NULL;
5860       SeqFeatXrefFree (xref);
5861     } else {
5862       last = &(xref->next);
5863     }
5864     xref = next;
5865   }
5866   if (grp == NULL) return TRUE;
5867   xgp = MemNew (sizeof (XrefGeneData));
5868   if (xgp == NULL) return TRUE;
5869   xgp->grp = grp;
5870   bsp = BioseqFindFromSeqLoc (sfp->location);
5871   xgp->slp = SeqLocMerge (bsp, sfp->location, NULL, TRUE, FALSE, FALSE);
5872   if (xgp->slp == NULL) {
5873     xgp->slp = AsnIoMemCopy (sfp->location, (AsnReadFunc) SeqLocAsnRead,
5874                              (AsnWriteFunc) SeqLocAsnWrite);
5875   } else {
5876     CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
5877     SetSeqLocPartial (xgp->slp, partial5, partial3);
5878   }
5879   /* if feature is pseudo, gene created from xref on feature should also be pseudo */
5880   xgp->pseudo = sfp->pseudo;
5881 
5882   ValNodeAddPointer (vnpp, 0, xgp);
5883   return TRUE;
5884 }
5885 
XrefToGene(IteM i)5886 static void XrefToGene (IteM i)
5887 
5888 {
5889   BaseFormPtr   bfp;
5890   BioseqPtr     bsp;
5891   Uint2         entityID = 0;
5892   GatherScope   gs;
5893   ValNodePtr    head;
5894   SeqEntryPtr   nsep;
5895   SeqFeatPtr    sfp;
5896   SelStructPtr  ssp;
5897   ValNodePtr    vnp;
5898   XrefGenePtr   xgp;
5899 
5900   head = NULL;
5901   ssp = ObjMgrGetSelected ();
5902   if (ssp == NULL) {
5903 #ifdef WIN_MAC
5904     bfp = currentFormDataPtr;
5905 #else
5906     bfp = GetObjectExtra (i);
5907 #endif
5908     if (bfp == NULL) {
5909       Message (MSG_ERROR, "XrefToGene error");
5910       return;
5911     }
5912     entityID = bfp->input_entityID;
5913     MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
5914     gs.seglevels = 1;
5915     MemSet((Pointer)(gs.ignore), (int)(TRUE), (size_t)(OBJ_MAX * sizeof(Boolean)));
5916     gs.ignore[OBJ_BIOSEQ] = FALSE;
5917     gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
5918     gs.ignore[OBJ_SEQANNOT] = FALSE;
5919     gs.ignore[OBJ_SEQFEAT] = FALSE;
5920     GatherEntity (bfp->input_entityID, (Pointer) &head, XrefToGeneCallback, &gs);
5921   } else {
5922     entityID = ssp->entityID;
5923     if (ssp->itemtype != OBJ_SEQFEAT) {
5924       Message (MSG_ERROR, "Feature must be selected");
5925       return;
5926     }
5927     GatherItem (ssp->entityID, ssp->itemID, ssp->itemtype, (Pointer) &head, XrefToGeneCallback);
5928   }
5929   if (head == NULL || entityID == 0) return;
5930   for (vnp = head; vnp != NULL; vnp = vnp->next) {
5931     xgp = (XrefGenePtr) vnp->data.ptrvalue;
5932     if (xgp != NULL) {
5933       bsp = GetBioseqGivenSeqLoc (xgp->slp, entityID);
5934       if (bsp != NULL) {
5935         nsep = SeqMgrGetSeqEntryForData (bsp);
5936         if (! ExtendGene (xgp->grp, nsep, xgp->slp)) {
5937           sfp = CreateNewFeature (nsep, NULL, SEQFEAT_GENE, NULL);
5938           if (sfp != NULL) {
5939             sfp->data.value.ptrvalue = (Pointer) xgp->grp;
5940             xgp->grp = NULL;
5941             sfp->location = SeqLocFree (sfp->location);
5942             sfp->location = xgp->slp;
5943             xgp->slp = NULL;
5944             sfp->pseudo = xgp->pseudo;
5945           }
5946         }
5947       }
5948       GeneRefFree (xgp->grp);
5949       SeqLocFree (xgp->slp);
5950     }
5951   }
5952   ValNodeFreeData (head);
5953   ObjMgrSetDirtyFlag (entityID, TRUE);
5954   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
5955 }
5956 
GeneToXrefCallback(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)5957 static void GeneToXrefCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
5958 
5959 {
5960   BaseFormPtr     bfp;
5961   BioseqPtr       bsp;
5962   BioseqSetPtr    bssp;
5963   SeqFeatPtr      gene;
5964   GeneRefPtr      grp;
5965   SeqFeatPtr      sfp;
5966   SeqAnnotPtr     sap;
5967   SeqFeatXrefPtr  xref;
5968 
5969   if (sep == NULL) return;
5970   bfp = (BaseFormPtr) mydata;
5971   if (bfp == NULL) return;
5972   if (IS_Bioseq (sep)) {
5973     bsp = (BioseqPtr) sep->data.ptrvalue;
5974     sap = bsp->annot;
5975   } else if (IS_Bioseq_set (sep)) {
5976     bssp = (BioseqSetPtr) sep->data.ptrvalue;
5977     sap = bssp->annot;
5978   } else return;
5979   while (sap != NULL) {
5980     if (sap->type == 1) {
5981       sfp = (SeqFeatPtr) sap->data;
5982       while (sfp != NULL) {
5983         if (sfp->data.choice != SEQFEAT_GENE) {
5984           FindGeneAndProtForCDS (bfp->input_entityID, sfp, &gene, NULL);
5985           if (gene != NULL) {
5986             grp = (GeneRefPtr) gene->data.value.ptrvalue;
5987             if (grp != NULL) {
5988               xref = SeqFeatXrefNew ();
5989               if (xref != NULL) {
5990                 xref->data.choice = SEQFEAT_GENE;
5991                 xref->data.value.ptrvalue = AsnIoMemCopy ((Pointer) grp,
5992                                                           (AsnReadFunc) GeneRefAsnRead,
5993                                                           (AsnWriteFunc) GeneRefAsnWrite);
5994                 xref->next = sfp->xref;
5995                 sfp->xref = xref;
5996               }
5997             }
5998           }
5999         }
6000         sfp = sfp->next;
6001       }
6002     }
6003     sap = sap->next;
6004   }
6005 }
6006 
GeneToXref(IteM i)6007 static void GeneToXref (IteM i)
6008 
6009 {
6010   BaseFormPtr  bfp;
6011   SeqEntryPtr  sep;
6012 
6013 #ifdef WIN_MAC
6014   bfp = currentFormDataPtr;
6015 #else
6016   bfp = GetObjectExtra (i);
6017 #endif
6018   if (bfp == NULL) {
6019     Message (MSG_ERROR, "GeneToXref error");
6020     return;
6021   }
6022   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
6023   if (sep == NULL) return;
6024   SeqEntryExplore (sep, (Pointer) bfp, GeneToXrefCallback);
6025   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
6026   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
6027 }
6028 
6029 typedef struct featurefieldforgenechoice
6030 {
6031   Int4    first_choice;
6032   Int4    second_choice;
6033   CharPtr field_txt;
6034 } FeatureFieldForGeneChoiceData, PNTR FeatureFieldForGeneChoicePtr;
6035 
FeatureFieldForGeneChoiceFree(FeatureFieldForGeneChoicePtr fcp)6036 static FeatureFieldForGeneChoicePtr FeatureFieldForGeneChoiceFree (FeatureFieldForGeneChoicePtr fcp)
6037 {
6038   if (fcp != NULL)
6039   {
6040     fcp->field_txt = MemFree (fcp->field_txt);
6041     fcp = MemFree (fcp);
6042   }
6043   return fcp;
6044 }
6045 
6046 typedef struct featuretogene
6047 {
6048   FEATURE_FORM_BLOCK
6049 
6050   DialoG *gene_src_dlg_list;
6051   Int4   num_choices;
6052   ValNodePtr feature_choices;
6053 
6054   TexT   label_txt;
6055   PopuP  genechoice;
6056   GrouP  qual_caps_grp;
6057   DialoG feature_dlg;
6058   DialoG filter_grp;
6059   DialoG accept_cancel;
6060 
6061   ButtoN single_interval_btn;
6062   ButtoN selected_features_only_btn;
6063 
6064   Boolean single_interval;
6065   FeatureFieldForGeneChoicePtr fcp;
6066 
6067 } FeatureToGeneData, PNTR FeatureToGenePtr;
6068 
GetGeneSrcDlgIndex(FeatureToGenePtr fgp)6069 static Int4 GetGeneSrcDlgIndex (FeatureToGenePtr fgp)
6070 {
6071   ValNodePtr vnp, check_vnp;
6072   Int4       rval = -1, i;
6073 
6074   if (fgp == NULL) return -1;
6075 
6076   vnp = DialogToPointer (fgp->feature_dlg);
6077   if (vnp == NULL)
6078   {
6079     return -1;
6080   }
6081 
6082   check_vnp = fgp->feature_choices;
6083   i = 0;
6084   while (check_vnp != NULL && check_vnp->choice != vnp->choice)
6085   {
6086     check_vnp = check_vnp->next;
6087     i++;
6088   }
6089   if (check_vnp != NULL)
6090   {
6091     rval = i;
6092   }
6093   ValNodeFreeData (vnp);
6094   return rval;
6095 }
6096 
EnableFeatureToGeneControls(Pointer userdata)6097 static void EnableFeatureToGeneControls (Pointer userdata)
6098 {
6099   Int4             i;
6100   FeatureToGenePtr fgp;
6101   FeatureFieldForGeneChoicePtr fcp;
6102 
6103   fgp = (FeatureToGenePtr) userdata;
6104   if (fgp == NULL) return;
6105   Disable (fgp->qual_caps_grp);
6106   Disable (fgp->genechoice);
6107 
6108   i = GetGeneSrcDlgIndex (fgp);
6109   if (i >= 0)
6110   {
6111     fcp = (FeatureFieldForGeneChoicePtr) DialogToPointer (fgp->gene_src_dlg_list [i]);
6112     if (fcp != NULL)
6113     {
6114       if (fcp->first_choice > 1 || !StringHasNoText (fcp->field_txt))
6115       {
6116         Enable (fgp->qual_caps_grp);
6117         Enable (fgp->genechoice);
6118       }
6119       fcp = FeatureFieldForGeneChoiceFree (fcp);
6120     }
6121   }
6122 }
6123 
6124 
6125 typedef struct featurefieldforgenedlg
6126 {
6127   DIALOG_MESSAGE_BLOCK
6128   PopuP first_choice_popup;
6129   PopuP second_choice_popup;
6130   TexT  label_txt;
6131   Nlm_ChangeNotifyProc change_notify;
6132   Pointer              change_userdata;
6133 } FeatureFieldForGeneDlgData, PNTR FeatureFieldForGeneDlgPtr;
6134 
ResetFeatureFieldForGeneDlg(FeatureFieldForGeneDlgPtr dlg)6135 static void ResetFeatureFieldForGeneDlg (FeatureFieldForGeneDlgPtr dlg)
6136 {
6137   if (dlg == NULL)
6138   {
6139     return;
6140   }
6141 
6142   SetValue (dlg->first_choice_popup, 1);
6143   SafeSetValue (dlg->second_choice_popup, 1);
6144   SetTitle (dlg->label_txt, "");
6145 }
6146 
FeatureFieldForGeneToDialog(DialoG d,Pointer userdata)6147 static void FeatureFieldForGeneToDialog (DialoG d, Pointer userdata)
6148 {
6149   FeatureFieldForGeneDlgPtr    dlg;
6150   FeatureFieldForGeneChoicePtr data;
6151 
6152   dlg = (FeatureFieldForGeneDlgPtr) GetObjectExtra (d);
6153   data = (FeatureFieldForGeneChoicePtr) userdata;
6154   if (dlg == NULL)
6155   {
6156     return;
6157   }
6158   ResetFeatureFieldForGeneDlg (dlg);
6159   if (data == NULL)
6160   {
6161     return;
6162   }
6163   if (data->first_choice > 0)
6164   {
6165     SetValue (dlg->first_choice_popup, data->first_choice);
6166   }
6167   if (data->second_choice > 0)
6168   {
6169     SafeSetValue (dlg->second_choice_popup, data->second_choice);
6170   }
6171   if (!StringHasNoText (data->field_txt))
6172   {
6173     SetTitle (dlg->label_txt, data->field_txt);
6174   }
6175 }
6176 
FeatureFieldForGeneFromDialog(DialoG d)6177 static Pointer FeatureFieldForGeneFromDialog (DialoG d)
6178 {
6179   FeatureFieldForGeneDlgPtr    dlg;
6180   FeatureFieldForGeneChoicePtr data;
6181 
6182   dlg = (FeatureFieldForGeneDlgPtr) GetObjectExtra (d);
6183   if (dlg == NULL)
6184   {
6185     return NULL;
6186   }
6187   data = (FeatureFieldForGeneChoicePtr) MemNew (sizeof (FeatureFieldForGeneChoiceData));
6188   if (data != NULL)
6189   {
6190     data->first_choice = GetValue (dlg->first_choice_popup);
6191     if (dlg->second_choice_popup != NULL)
6192     {
6193       data->second_choice = GetValue (dlg->second_choice_popup);
6194     }
6195     else
6196     {
6197       data->second_choice = 0;
6198     }
6199     if (TextHasNoText (dlg->label_txt))
6200     {
6201       data->field_txt = NULL;
6202     }
6203     else
6204     {
6205       data->field_txt = SaveStringFromText (dlg->label_txt);
6206     }
6207   }
6208   return data;
6209 }
6210 
FeatureFieldForGeneChange(FeatureFieldForGeneDlgPtr dlg)6211 static void FeatureFieldForGeneChange (FeatureFieldForGeneDlgPtr dlg)
6212 {
6213   if (dlg == NULL)
6214   {
6215     return;
6216   }
6217   if (GetValue (dlg->first_choice_popup) > 1)
6218   {
6219     SafeEnable (dlg->second_choice_popup);
6220   }
6221   else
6222   {
6223     SafeDisable (dlg->second_choice_popup);
6224   }
6225   if (dlg->change_notify != NULL)
6226   {
6227     (dlg->change_notify) (dlg->change_userdata);
6228   }
6229 }
6230 
FeatureFieldForGeneChangePopup(PopuP p)6231 static void FeatureFieldForGeneChangePopup (PopuP p)
6232 {
6233   FeatureFieldForGeneDlgPtr  dlg;
6234 
6235   dlg = (FeatureFieldForGeneDlgPtr) GetObjectExtra (p);
6236   FeatureFieldForGeneChange (dlg);
6237 }
6238 
FeatureFieldForGeneChangeText(TexT t)6239 static void FeatureFieldForGeneChangeText (TexT t)
6240 {
6241   FeatureFieldForGeneDlgPtr  dlg;
6242 
6243   dlg = (FeatureFieldForGeneDlgPtr) GetObjectExtra (t);
6244   FeatureFieldForGeneChange (dlg);
6245 }
6246 
MakeFieldChoicePopup(GrouP g,Int4 featdef_choice,Pointer extradata)6247 static PopuP MakeFieldChoicePopup (GrouP g, Int4 featdef_choice, Pointer extradata)
6248 {
6249   PopuP p;
6250 
6251   p = PopupList (g, TRUE, FeatureFieldForGeneChangePopup);
6252   SetObjectExtra (p, extradata, NULL);
6253 
6254   if (featdef_choice == FEATDEF_CDS
6255       || featdef_choice == FEATDEF_tRNA
6256       || featdef_choice == FEATDEF_rRNA
6257       || featdef_choice == FEATDEF_misc_RNA
6258       || featdef_choice == FEATDEF_mRNA)
6259   {
6260     PopupItem (p, "None");
6261     PopupItem (p, "Comment");
6262     PopupItem (p, "Product");
6263   }
6264   else
6265   {
6266     PopupItem (p, "None");
6267     PopupItem (p, "Comment");
6268   }
6269   SetValue (p, 1);
6270   return p;
6271 }
6272 
6273 static DialoG
FeatureFieldForGeneDialog(GrouP parent,Int4 featdef_choice,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)6274 FeatureFieldForGeneDialog
6275 (GrouP parent,
6276  Int4  featdef_choice,
6277  Nlm_ChangeNotifyProc change_notify,
6278  Pointer              change_userdata)
6279 {
6280   FeatureFieldForGeneDlgPtr  dlg;
6281   GrouP                     p;
6282 
6283   dlg = (FeatureFieldForGeneDlgPtr) MemNew (sizeof (FeatureFieldForGeneDlgData));
6284   if (dlg == NULL)
6285   {
6286     return NULL;
6287   }
6288 
6289   p = NormalGroup (parent, 2, 0, "Select qualifier to use in gene", NULL, NULL);
6290   SetObjectExtra (p, dlg, StdCleanupExtraProc);
6291 
6292   dlg->dialog = (DialoG) p;
6293   dlg->todialog = FeatureFieldForGeneToDialog;
6294   dlg->fromdialog = FeatureFieldForGeneFromDialog;
6295   dlg->dialogmessage = NULL;
6296   dlg->testdialog = NULL;
6297   dlg->change_notify = change_notify;
6298   dlg->change_userdata = change_userdata;
6299 
6300   StaticPrompt (p, "1st Choice", 0, 0, programFont, 'c');
6301   dlg->first_choice_popup = MakeFieldChoicePopup (p, featdef_choice, dlg);
6302 
6303   if (featdef_choice == FEATDEF_CDS
6304       || featdef_choice == FEATDEF_tRNA
6305       || featdef_choice == FEATDEF_rRNA
6306       || featdef_choice == FEATDEF_misc_RNA
6307       || featdef_choice == FEATDEF_mRNA)
6308   {
6309     StaticPrompt (p, "2nd Choice", 0, 0, programFont, 'c');
6310     dlg->second_choice_popup = MakeFieldChoicePopup (p, featdef_choice, dlg);
6311     Disable (dlg->second_choice_popup);
6312   }
6313   else
6314   {
6315     dlg->second_choice_popup = NULL;
6316   }
6317 
6318   StaticPrompt (p, "Use this string:", 0, 0, programFont, 'c');
6319   dlg->label_txt = DialogText (p, "", 10, FeatureFieldForGeneChangeText);
6320   SetObjectExtra (dlg->label_txt, dlg, NULL);
6321 
6322   return (DialoG) p;
6323 }
6324 
GetGeneSrcChoice(SeqFeatPtr sfp,Int4 choice)6325 static CharPtr GetGeneSrcChoice (SeqFeatPtr sfp, Int4 choice)
6326 {
6327   CharPtr           src_txt = NULL;
6328   RnaRefPtr         rrp;
6329   SeqMgrFeatContext fcontext;
6330 
6331   if (sfp == NULL || choice < 2)
6332   {
6333     return NULL;
6334   }
6335 
6336   if (choice == 2 && !StringHasNoText (sfp->comment))
6337   {
6338     src_txt = StringSave (sfp->comment);
6339   }
6340   else if (choice == 3)
6341   {
6342     if (sfp->idx.subtype == FEATDEF_tRNA)
6343     {
6344       sfp = SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL,
6345                                      0, 0, sfp, &fcontext);
6346       if (!StringHasNoText (fcontext.label))
6347       {
6348         src_txt = (CharPtr) MemNew (StringLen (fcontext.label) + 6);
6349         if (src_txt != NULL)
6350         {
6351           sprintf (src_txt, "tRNA-%s", fcontext.label);
6352         }
6353       }
6354     }
6355     else if (sfp->idx.subtype == FEATDEF_CDS
6356              || sfp->idx.subtype == FEATDEF_mRNA)
6357     {
6358       sfp = SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL,
6359                                      0, 0, sfp, &fcontext);
6360       if (!StringHasNoText (fcontext.label))
6361       {
6362         src_txt = StringSave (fcontext.label);
6363       }
6364     }
6365     else if (sfp->data.choice == SEQFEAT_RNA)
6366     {
6367       rrp = (RnaRefPtr) (sfp->data.value.ptrvalue);
6368       if (rrp != NULL && rrp->ext.choice == 1
6369           && !StringHasNoText (rrp->ext.value.ptrvalue))
6370       {
6371         src_txt = StringSave (rrp->ext.value.ptrvalue);
6372       }
6373     }
6374   }
6375   return src_txt;
6376 }
6377 
GetGeneSrc(SeqFeatPtr sfp,FeatureFieldForGeneChoicePtr fcp)6378 static CharPtr GetGeneSrc (SeqFeatPtr sfp, FeatureFieldForGeneChoicePtr fcp)
6379 {
6380   CharPtr src_txt = NULL;
6381 
6382   if (sfp == NULL || fcp == NULL)
6383   {
6384     return NULL;
6385   }
6386 
6387   src_txt = GetGeneSrcChoice (sfp, fcp->first_choice);
6388   if (src_txt == NULL)
6389   {
6390     src_txt = GetGeneSrcChoice (sfp, fcp->second_choice);
6391   }
6392   if (src_txt == NULL && !StringHasNoText (fcp->field_txt))
6393   {
6394     src_txt = StringSave (fcp->field_txt);
6395   }
6396   return src_txt;
6397 }
6398 
IsBioseqmRNA(BioseqPtr bsp)6399 static Boolean IsBioseqmRNA (BioseqPtr bsp)
6400 {
6401   SeqDescrPtr       sdp;
6402   SeqMgrDescContext context;
6403   MolInfoPtr        mip;
6404 
6405   sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_molinfo, &context);
6406   if (sdp == NULL || sdp->data.ptrvalue == NULL)
6407   {
6408     return FALSE;
6409   }
6410 
6411   mip = (MolInfoPtr) sdp->data.ptrvalue;
6412   if (mip->biomol == 3)
6413   {
6414     return TRUE;
6415   }
6416   return FALSE;
6417 }
6418 
FeatureToGeneCallback(SeqFeatPtr sfp,Pointer userdata,FilterSetPtr fsp)6419 static void FeatureToGeneCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
6420 {
6421   SeqFeatPtr         gene, overlap_gene;
6422   GeneRefPtr         grp;
6423   Boolean            partial5, partial3;
6424   FeatureToGenePtr   fgp;
6425   CharPtr            gene_val = NULL;
6426   Int4               i;
6427   BioseqPtr          bsp;
6428   CharPtr            cp;
6429   SeqLocPtr          gene_location;
6430 
6431   if (sfp == NULL || userdata == NULL) return;
6432   fgp = (FeatureToGenePtr) userdata;
6433 
6434   if (SeqMgrGetGeneXref (sfp) != NULL) return;
6435 
6436   bsp = BioseqFindFromSeqLoc (sfp->location);
6437   if (bsp == NULL) return;
6438 
6439   gene_location = SeqLocMerge (bsp, sfp->location, NULL, fgp->single_interval, FALSE, FALSE);
6440   if (gene_location == NULL) return;
6441 
6442   overlap_gene = SeqMgrGetOverlappingGene (sfp->location, NULL);
6443   if (overlap_gene != NULL && SeqLocCompare (gene_location, overlap_gene->location) == SLC_A_EQ_B)
6444   {
6445     gene_location = SeqLocFree (gene_location);
6446     return;
6447   }
6448 
6449   if (IsBioseqmRNA (bsp))
6450   {
6451     gene_location = SeqLocFree (gene_location);
6452     gene_location = SeqLocIntNew (0, bsp->length - 1,
6453                                   SeqLocStrand (sfp->location),
6454                                   SeqIdFindBest (bsp->id, 0));
6455   }
6456 
6457   gene_val = GetGeneSrc (sfp, fgp->fcp);
6458 
6459   if (gene_val != NULL)
6460   {
6461   	/* apply capitalization */
6462 	  switch (GetValue (fgp->qual_caps_grp))
6463   	{
6464   	  case 1:
6465   	    /* do nothing, leave capitalization as is */
6466   	    break;
6467   	  case 2:
6468   	    /* capitalize first letter */
6469   	    gene_val [0] = toupper (gene_val[0]);
6470   	    break;
6471   	  case 3:
6472   	  	/* capitalize all letters */
6473   	  	for (cp = gene_val; *cp != 0; cp++)
6474   	  	{
6475   	  	  *cp = toupper (*cp);
6476   	  	}
6477   	  	break;
6478   	}
6479   }
6480 
6481   gene = SeqFeatNew ();
6482   if (gene == NULL) return;
6483 
6484   grp = GeneRefNew ();
6485   if (grp == NULL) return;
6486   i = GetValue (fgp->genechoice);
6487   switch (i)
6488   {
6489   	case 1:
6490   	  grp->locus = gene_val;
6491   	  break;
6492   	case 2:
6493   	  grp->locus_tag = gene_val;
6494   	  break;
6495   	case 3:
6496   	  grp->desc = gene_val;
6497   	  break;
6498   	case 4:
6499   	  grp->allele = gene_val;
6500   	  break;
6501   	default:
6502   	  gene->comment = gene_val;
6503   	  break;
6504   }
6505 
6506   gene->data.choice = SEQFEAT_GENE;
6507   gene->data.value.ptrvalue = (Pointer) grp;
6508   gene->location = gene_location;
6509   CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
6510   SetSeqLocPartial (gene->location, partial5, partial3);
6511   gene->partial = sfp->partial;
6512   gene->next = sfp->next;
6513   sfp->next = gene;
6514 }
6515 
FeatureToGeneAccept(Pointer userdata)6516 static Boolean FeatureToGeneAccept (Pointer userdata)
6517 {
6518   FeatureToGenePtr  fgp;
6519   SeqEntryPtr       sep;
6520   SelStructPtr      sel;
6521   SeqFeatPtr        sfp;
6522   SeqMgrFeatContext fcontext;
6523   FilterSetPtr      fsp;
6524   Int4              i, featdef_choice;
6525   ValNodePtr        vnp;
6526 
6527   fgp = (FeatureToGenePtr) userdata;
6528   if (fgp == NULL) return FALSE;
6529 
6530   vnp = DialogToPointer (fgp->feature_dlg);
6531   if (vnp == NULL)
6532   {
6533     return FALSE;
6534   }
6535   featdef_choice = vnp->choice;
6536   vnp = ValNodeFreeData (vnp);
6537 
6538   i = GetGeneSrcDlgIndex (fgp);
6539   if (i < 0)
6540   {
6541     return FALSE;
6542   }
6543 
6544   fgp->fcp = DialogToPointer (fgp->gene_src_dlg_list [i]);
6545 
6546   fsp = DialogToPointer (fgp->filter_grp);
6547 
6548   sep = GetTopSeqEntryForEntityID (fgp->input_entityID);
6549   if (sep == NULL) return FALSE;
6550   fgp->single_interval = GetStatus (fgp->single_interval_btn);
6551   if (GetStatus (fgp->selected_features_only_btn))
6552   {
6553     sel = ObjMgrGetSelected ();
6554     while (sel != NULL)
6555     {
6556       if (sel->itemtype == OBJ_SEQFEAT)
6557       {
6558         sfp = SeqMgrGetDesiredFeature (sel->entityID, NULL, sel->itemID, 0, NULL, &fcontext);
6559         if (sfp != NULL)
6560         {
6561           FeatureToGeneCallback (sfp, fgp, NULL);
6562         }
6563       }
6564       sel = sel->next;
6565     }
6566   }
6567   else
6568   {
6569     OperateOnSeqEntryConstrainedObjects (sep, fsp, FeatureToGeneCallback,
6570                                          NULL, 0, featdef_choice, 0, fgp);
6571   }
6572 
6573   FilterSetFree (fsp);
6574   fgp->fcp = FeatureFieldForGeneChoiceFree (fgp->fcp);
6575 
6576   ObjMgrSetDirtyFlag (fgp->input_entityID, TRUE);
6577   ObjMgrSendMsg (OM_MSG_UPDATE, fgp->input_entityID, 0, 0);
6578   return TRUE;
6579 }
6580 
ChangeGeneFeatureSelection(Pointer userdata)6581 static void ChangeGeneFeatureSelection (Pointer userdata)
6582 {
6583   FeatureToGenePtr  fgp;
6584   Int4              i;
6585 
6586   fgp = (FeatureToGenePtr) userdata;
6587   if (fgp == NULL)
6588   {
6589     return;
6590   }
6591 
6592   for (i = 0; i < fgp->num_choices; i++)
6593   {
6594     Hide (fgp->gene_src_dlg_list [i]);
6595   }
6596 
6597   i = GetGeneSrcDlgIndex (fgp);
6598 
6599   if (i < 0)
6600   {
6601     DisableAcceptCancelDialogAccept (fgp->accept_cancel);
6602   }
6603   else
6604   {
6605     EnableAcceptCancelDialogAccept (fgp->accept_cancel);
6606     Show (fgp->gene_src_dlg_list [i]);
6607   }
6608   EnableFeatureToGeneControls (fgp);
6609 }
6610 
CleanupFeatureToGeneForm(GraphiC g,VoidPtr data)6611 static void CleanupFeatureToGeneForm (GraphiC g, VoidPtr data)
6612 {
6613   FeatureToGenePtr fgp;
6614 
6615   fgp = (FeatureToGenePtr) data;
6616   if (fgp != NULL)
6617   {
6618     fgp->feature_choices = ValNodeFreeData (fgp->feature_choices);
6619     MemFree (fgp);
6620   }
6621 }
6622 
FeatureToGeneClearText(Pointer userdata)6623 static void FeatureToGeneClearText (Pointer userdata)
6624 {
6625   FeatureToGenePtr             fgp;
6626   Int4                         j;
6627   FilterSetPtr                 fsp;
6628   FeatureFieldForGeneChoicePtr fcp;
6629 
6630   fgp = (FeatureToGenePtr) userdata;
6631   if (fgp == NULL)
6632   {
6633     return;
6634   }
6635 
6636   for (j = 0; j < fgp->num_choices; j++)
6637   {
6638     fcp = (FeatureFieldForGeneChoicePtr) DialogToPointer (fgp->gene_src_dlg_list [j]);
6639     if (fcp != NULL)
6640     {
6641       fcp->field_txt = MemFree (fcp->field_txt);
6642     }
6643     PointerToDialog (fgp->gene_src_dlg_list [j], fcp);
6644     FeatureFieldForGeneChoiceFree (fcp);
6645   }
6646 
6647   fsp = (FilterSetPtr) DialogToPointer (fgp->filter_grp);
6648   FilterSetClearText (fsp);
6649   PointerToDialog (fgp->filter_grp, fsp);
6650   FilterSetFree (fsp);
6651   EnableFeatureToGeneControls (fgp);
6652 }
6653 
FeatureToGeneClear(Pointer userdata)6654 static void FeatureToGeneClear (Pointer userdata)
6655 {
6656   FeatureToGenePtr  fgp;
6657   Int4              j;
6658 
6659   fgp = (FeatureToGenePtr) userdata;
6660   if (fgp == NULL)
6661   {
6662     return;
6663   }
6664 
6665   PointerToDialog (fgp->feature_dlg, NULL);
6666   for (j = 0; j < fgp->num_choices; j++)
6667   {
6668     PointerToDialog (fgp->gene_src_dlg_list [j], NULL);
6669   }
6670   PointerToDialog (fgp->filter_grp, NULL);
6671 
6672   SetValue (fgp->qual_caps_grp, 1);
6673   SetValue (fgp->genechoice, 1);
6674   SetStatus (fgp->single_interval_btn, TRUE);
6675   SetStatus (fgp->selected_features_only_btn, FALSE);
6676 
6677   ChangeGeneFeatureSelection (fgp);
6678   EnableFeatureToGeneControls (fgp);
6679 }
6680 
FeatureToGene(IteM i)6681 static void FeatureToGene (IteM i)
6682 {
6683   BaseFormPtr       bfp;
6684   FeatureToGenePtr  fgp;
6685   WindoW            w;
6686   Int4              j;
6687   GrouP             h, k, m, n;
6688   ValNodePtr        vnp;
6689   SeqEntryPtr       sep;
6690 
6691 #ifdef WIN_MAC
6692   bfp = currentFormDataPtr;
6693 #else
6694   bfp = GetObjectExtra (i);
6695 #endif
6696   if (bfp == NULL) {
6697     Message (MSG_ERROR, "Feature to Gene error");
6698     return;
6699   }
6700 
6701   fgp = (FeatureToGenePtr) MemNew (sizeof (FeatureToGeneData));
6702   if (fgp == NULL) return;
6703   fgp->input_entityID = bfp->input_entityID;
6704   w = FixedWindow (-50, -33, -10, -10, "Feature to Gene", StdCloseWindowProc);
6705   SetObjectExtra (w, fgp, CleanupFeatureToGeneForm);
6706   fgp->form = (ForM) w;
6707 
6708   h = HiddenGroup (w, -1, 0, NULL);
6709   SetGroupSpacing (h, 10, 10);
6710 
6711   sep = GetTopSeqEntryForEntityID(bfp->input_entityID);
6712   fgp->feature_dlg = FeatureSelectionDialogEx (h, FALSE, sep, ChangeGeneFeatureSelection, fgp);
6713   k = HiddenGroup (h, 0, 0, NULL);
6714 
6715   fgp->feature_choices = BuildFeatureDialogList (TRUE, sep);
6716   fgp->num_choices = ValNodeLen (fgp->feature_choices);
6717   fgp->gene_src_dlg_list = (DialoG *) MemNew (fgp->num_choices * sizeof (DialoG));
6718 
6719   for (j = 0, vnp = fgp->feature_choices;
6720        j < fgp->num_choices && vnp != NULL;
6721        j++, vnp = vnp->next)
6722   {
6723     fgp->gene_src_dlg_list [j] = FeatureFieldForGeneDialog (k, vnp->choice,
6724                                                             EnableFeatureToGeneControls,
6725                                                             fgp);
6726   }
6727 
6728   fgp->qual_caps_grp = NormalGroup (h, 3, 0,
6729                      "Capitalization for gene", NULL, NULL);
6730   RadioButton (fgp->qual_caps_grp, "As is");
6731   RadioButton (fgp->qual_caps_grp, "Capitalize first initial");
6732   RadioButton (fgp->qual_caps_grp, "Capitalize all");
6733   SetValue (fgp->qual_caps_grp, 1);
6734   Disable (fgp->qual_caps_grp);
6735   m = HiddenGroup (h, 2, 0, NULL);
6736   StaticPrompt (m, "Select gene qualifier to populate", 0,0, programFont, 'c');
6737   fgp->genechoice = PopupList (m, TRUE, NULL);
6738   PopupItem (fgp->genechoice, "locus");
6739   PopupItem (fgp->genechoice, "locus_tag");
6740   PopupItem (fgp->genechoice, "gene description");
6741   PopupItem (fgp->genechoice, "allele");
6742   PopupItem (fgp->genechoice, "gene comment");
6743   SetValue (fgp->genechoice, 1);
6744   Disable (fgp->genechoice);
6745 
6746   n = HiddenGroup (h, 2, 0, NULL);
6747   fgp->single_interval_btn = CheckBox (n, "Create gene with single interval location", NULL);
6748   SetStatus (fgp->single_interval_btn, TRUE);
6749   fgp->selected_features_only_btn = CheckBox (n, "Only create genes for selected features", NULL);
6750   SetStatus (fgp->selected_features_only_btn, FALSE);
6751 
6752   fgp->filter_grp = FilterGroup (h, TRUE, FALSE, FALSE, FALSE, FALSE, "Where feature field contains");
6753 
6754   fgp->accept_cancel = AcceptCancelDialog (h, FeatureToGeneAccept, NULL, FeatureToGeneClear, FeatureToGeneClearText, (Pointer)fgp, w);
6755 
6756   AlignObjects (ALIGN_CENTER, (HANDLE) fgp->feature_dlg,
6757                               (HANDLE) k,
6758                               (HANDLE) fgp->qual_caps_grp,
6759                               (HANDLE) m,
6760                               (HANDLE) n,
6761                               (HANDLE) fgp->filter_grp,
6762                               (HANDLE) fgp->accept_cancel,
6763                               NULL);
6764 
6765   RealizeWindow (w);
6766   Show (w);
6767   Update ();
6768   ChangeGeneFeatureSelection (fgp);
6769 }
6770 
6771 
6772 typedef struct featuretocdsform
6773 {
6774   FEATURE_FORM_BLOCK
6775   PopuP   feature_choice;
6776 
6777   DialoG  gene_field;
6778   DialoG  exon_field;
6779   DialoG  mrna_field;
6780   GrouP   qual_caps_grp;
6781   TexT    append_text;
6782   ButtoN  accept_btn;
6783   ButtoN  fuse_multiple_btn;
6784   ButtoN  include_utr_btn;
6785   DialoG  constraint_dlg;
6786   GrouP   name_choice_grp;
6787 
6788   Int4       featdef_choice;
6789   ValNodePtr gene_field_list;
6790   ValNodePtr mrna_field_list;
6791   ValNodePtr exon_field_list;
6792   CharPtr    append_string;
6793   Int4       caps_choice;
6794   Boolean    fuse_multiple;
6795   Boolean    makemRNA;
6796   Boolean    include_utr;
6797   SeqEntryPtr sep;
6798   LogInfoData lid;
6799   ConstraintChoiceSetPtr constraint;
6800 
6801 } FeatureToCDSFormData, PNTR FeatureToCDSFormPtr;
6802 
6803 #define FEATURE_TO_CDS_GENE 1
6804 #define FEATURE_TO_CDS_MRNA 2
6805 #define FEATURE_TO_CDS_EXON 3
6806 #define FEATURE_TO_CDS_5UTR 4
6807 #define FEATURE_TO_CDS_3UTR 5
6808 
EnableFeatureToCDSControls(Pointer data)6809 static void EnableFeatureToCDSControls (Pointer data)
6810 {
6811   FeatureToCDSFormPtr    fp;
6812   Int4                   feature_choice;
6813   Boolean                need_name_string = FALSE;
6814   ValNodePtr             missing = NULL;
6815   CharPtr                cp;
6816 
6817   fp = (FeatureToCDSFormPtr) data;
6818   if (fp == NULL)
6819   {
6820     return;
6821   }
6822   Enable (fp->accept_btn);
6823   feature_choice = GetValue (fp->feature_choice);
6824   switch (feature_choice)
6825   {
6826     case FEATURE_TO_CDS_GENE:
6827       missing = TestDialog (fp->gene_field);
6828       if (missing != NULL)
6829       {
6830         need_name_string = TRUE;
6831         ValNodeFree (missing);
6832       }
6833       break;
6834     case FEATURE_TO_CDS_EXON:
6835       missing = DialogToPointer (fp->exon_field);
6836       if (missing == NULL)
6837       {
6838         need_name_string = TRUE;
6839       }
6840       ValNodeFree (missing);
6841       break;
6842     case FEATURE_TO_CDS_MRNA:
6843       missing = DialogToPointer (fp->mrna_field);
6844       if (missing == NULL)
6845       {
6846         need_name_string = TRUE;
6847       }
6848       ValNodeFree (missing);
6849       break;
6850     case FEATURE_TO_CDS_5UTR:
6851     case FEATURE_TO_CDS_3UTR:
6852       need_name_string = TRUE;
6853       break;
6854   }
6855 
6856   if (need_name_string)
6857   {
6858     Disable (fp->qual_caps_grp);
6859     cp = SaveStringFromText (fp->append_text);
6860     if (StringHasNoText (cp))
6861     {
6862       Disable (fp->accept_btn);
6863     }
6864     MemFree (cp);
6865   }
6866   else
6867   {
6868     Enable (fp->qual_caps_grp);
6869   }
6870 }
6871 
EnableFeatureToCDSControlsText(TexT t)6872 static void EnableFeatureToCDSControlsText (TexT t)
6873 {
6874   FeatureToCDSFormPtr    fp;
6875 
6876   fp = (FeatureToCDSFormPtr) GetObjectExtra (t);
6877   EnableFeatureToCDSControls (fp);
6878 }
6879 
ChangeFeatureToCDS(PopuP p)6880 static void ChangeFeatureToCDS (PopuP p)
6881 {
6882   FeatureToCDSFormPtr    fp;
6883   Int4                   feature_choice;
6884 
6885   fp = (FeatureToCDSFormPtr) GetObjectExtra (p);
6886   if (fp != NULL)
6887   {
6888     feature_choice = GetValue (fp->feature_choice);
6889     switch (feature_choice)
6890     {
6891       case FEATURE_TO_CDS_GENE:
6892         Show (fp->gene_field);
6893         Hide (fp->mrna_field);
6894         Hide (fp->exon_field);
6895         Show (fp->name_choice_grp);
6896         break;
6897       case FEATURE_TO_CDS_MRNA:
6898         Show (fp->mrna_field);
6899         Hide (fp->gene_field);
6900         Hide (fp->exon_field);
6901         Show (fp->name_choice_grp);
6902         break;
6903       case FEATURE_TO_CDS_EXON:
6904         Show (fp->exon_field);
6905         Hide (fp->mrna_field);
6906         Hide (fp->gene_field);
6907         Show (fp->name_choice_grp);
6908         break;
6909       case FEATURE_TO_CDS_5UTR:
6910       case FEATURE_TO_CDS_3UTR:
6911       default:
6912         Hide (fp->name_choice_grp);
6913         break;
6914     }
6915   }
6916   EnableFeatureToCDSControls (fp);
6917 }
6918 
CleanupFeatureToCDSPage(GraphiC g,VoidPtr data)6919 static void CleanupFeatureToCDSPage (GraphiC g, VoidPtr data)
6920 {
6921   FeatureToCDSFormPtr fp;
6922 
6923   fp = (FeatureToCDSFormPtr) data;
6924   if (fp != NULL)
6925   {
6926     fp->append_string = MemFree (fp->append_string);
6927     fp->gene_field_list = ValNodeFree (fp->gene_field_list);
6928     fp->mrna_field_list = ValNodeFree (fp->mrna_field_list);
6929     fp->exon_field_list = ValNodeFree (fp->exon_field_list);
6930     MemFree (fp);
6931   }
6932 }
6933 
LogFeatureToCDSNoProtein(FeatureToCDSFormPtr fp,CharPtr feature_label,SeqIdPtr sip)6934 static void LogFeatureToCDSNoProtein (FeatureToCDSFormPtr fp, CharPtr feature_label, SeqIdPtr sip)
6935 {
6936   Char       id [41];
6937 
6938   if (fp == NULL || fp->lid.fp == NULL || sip == NULL) return;
6939 
6940   id [0] = '\0';
6941   SeqIdWrite (SeqIdFindBest (sip, 0), id, PRINTID_FASTA_LONG, sizeof (id) - 1);
6942 
6943   if (StringHasNoText (feature_label))
6944   {
6945     fprintf (fp->lid.fp, "No protein added for unlabeled feature on sequence %s\n", id);
6946   }
6947   else
6948   {
6949     fprintf (fp->lid.fp, "No protein added for %s on sequence %s\n", feature_label, id);
6950   }
6951   fp->lid.data_in_log = TRUE;
6952 }
6953 
GetNewProteinName(SeqFeatPtr sfp,FeatureToCDSFormPtr fp)6954 static CharPtr GetNewProteinName (SeqFeatPtr sfp, FeatureToCDSFormPtr fp)
6955 {
6956   SeqMgrFeatContext context;
6957   CharPtr           prot_name_src = NULL;
6958   CharPtr           protName = NULL;
6959   Int4              prot_len;
6960   CharPtr           cp;
6961 
6962   if (sfp == NULL || fp == NULL || sfp->idx.subtype != fp->featdef_choice)
6963   {
6964     return NULL;
6965   }
6966 
6967   if (SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL,
6968                                0, 0, sfp, &context) == NULL) return NULL;
6969 
6970   /* determine the new protein name */
6971   if (fp->featdef_choice == FEATDEF_GENE)
6972   {
6973     prot_name_src = GetGeneFieldString (sfp, fp->gene_field_list, NULL);
6974   }
6975   else if (fp->featdef_choice == FEATDEF_mRNA)
6976   {
6977     prot_name_src = GetmRNAFieldString (sfp, fp->mrna_field_list, NULL);
6978   }
6979   else if (fp->featdef_choice == FEATDEF_exon)
6980   {
6981     prot_name_src = GetExonFieldString (sfp, fp->exon_field_list);
6982   }
6983   else if (fp->featdef_choice == FEATDEF_CDS)
6984   {
6985     prot_name_src = GetCDSFieldString(sfp, fp->mrna_field_list, NULL);
6986   }
6987 
6988   if (StringHasNoText (prot_name_src) && StringHasNoText (fp->append_string))
6989   {
6990   	return NULL;
6991   }
6992 
6993   prot_len = StringLen (prot_name_src) + StringLen (fp->append_string) + 2;
6994 
6995   /* add one to length for terminating null */
6996   protName = (CharPtr) MemNew (prot_len * sizeof (Char));
6997   if (protName == NULL) return NULL;
6998 
6999   if (!StringHasNoText (prot_name_src))
7000   {
7001     StringCpy (protName, prot_name_src);
7002   	/* apply capitalization */
7003     switch (fp->caps_choice)
7004   	{
7005   	  case 1:
7006   	    /* do nothing, leave capitalization as is */
7007   	    break;
7008   	  case 2:
7009   	    /* capitalize first letter */
7010   	    protName [0] = toupper (protName[0]);
7011   	    break;
7012   	  case 3:
7013   	  	/* capitalize all letters */
7014   	  	for (cp = protName; *cp != 0; cp++)
7015   	  	{
7016   	  	  *cp = toupper (*cp);
7017   	  	}
7018   	  	break;
7019   	}
7020   	if (!StringHasNoText (fp->append_string))
7021   	{
7022   	  StringCat (protName, " ");
7023   	}
7024   }
7025   prot_name_src = MemFree (prot_name_src);
7026   if (!StringHasNoText (fp->append_string))
7027   {
7028     StringCat (protName, fp->append_string);
7029   }
7030   return protName;
7031 }
7032 
MakeCDS(SeqLocPtr location,CharPtr name_str,Uint2 entityID,SeqEntryPtr sep,LogInfoPtr lip)7033 static SeqFeatPtr MakeCDS(SeqLocPtr location, CharPtr name_str, Uint2 entityID, SeqEntryPtr sep, LogInfoPtr lip)
7034 {
7035   SeqFeatPtr        cds, sfp;
7036   Int2              genCode;
7037   CdRegionPtr       crp;
7038   ByteStorePtr      bs;
7039   BioseqPtr         bsp;
7040   SeqEntryPtr       psep, nsep, old, topsep;
7041   MolInfoPtr        mip;
7042   ProtRefPtr        prp;
7043   Char              ch;
7044   ValNodePtr        descr;
7045   Int2              i;
7046   Boolean           partial5, partial3;
7047   CharPtr           prot;
7048   CharPtr           ptr;
7049   ValNodePtr        vnp;
7050 
7051   cds = SeqFeatNew ();
7052 
7053   CheckSeqLocForPartial (location, &partial5, &partial3);
7054 
7055   if (cds == NULL) return NULL;
7056   cds->data.choice = SEQFEAT_CDREGION;
7057 
7058   genCode = SeqEntryToGeneticCode (sep, NULL, NULL, 0);
7059   crp = CreateNewCdRgn (1, FALSE, genCode);
7060   if (crp == NULL) {
7061     return NULL;
7062   }
7063 
7064   cds->data.value.ptrvalue = (Pointer) crp;
7065   cds->location = SeqLocFree (cds->location);
7066   cds->location = AsnIoMemCopy ((Pointer) location,
7067                                 (AsnReadFunc) SeqLocAsnRead,
7068                                 (AsnWriteFunc) SeqLocAsnWrite);
7069   cds->partial = partial5 | partial3;
7070 
7071   if (!SetBestFrameByLocation (cds)) {
7072     LogCDSAmbiguousFrame (lip, cds);
7073   }
7074 
7075   bs = ProteinFromCdRegionEx (cds, TRUE, FALSE);
7076   if (bs != NULL) {
7077     prot = BSMerge (bs, NULL);
7078     bs = BSFree (bs);
7079     if (prot != NULL) {
7080       ptr = prot;
7081       ch = *ptr;
7082       while (ch != '\0') {
7083         *ptr = TO_UPPER (ch);
7084         ptr++;
7085         ch = *ptr;
7086       }
7087       i = (Int2) StringLen (prot);
7088       if (i > 0 && prot [i - 1] == '*') {
7089         prot [i - 1] = '\0';
7090       }
7091       bs = BSNew (1000);
7092 	  if (bs != NULL) {
7093         ptr = prot;
7094         BSWrite (bs, (VoidPtr) ptr, (Int4) StringLen (ptr));
7095       }
7096     }
7097   }
7098   bsp = BioseqNew ();
7099   if (bsp == NULL) return NULL;
7100   bsp->repr = Seq_repr_raw;
7101   bsp->mol = Seq_mol_aa;
7102   bsp->seq_data_type = Seq_code_ncbieaa;
7103   bsp->seq_data = (SeqDataPtr) bs;
7104   bsp->length = BSLen (bs);
7105   bs = NULL;
7106   old = SeqEntrySetScope (NULL);
7107   bsp->id = MakeNewProteinSeqId (cds->location, NULL);
7108   SeqMgrAddToBioseqIndex (bsp);
7109   SeqEntrySetScope (old);
7110   psep = SeqEntryNew ();
7111   if (psep != NULL) {
7112     psep->choice = 1;
7113     psep->data.ptrvalue = (Pointer) bsp;
7114     SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) bsp, psep);
7115     mip = MolInfoNew ();
7116     if (mip != NULL) {
7117       mip->biomol = 8;
7118       mip->tech = 8;
7119       if (partial5 && partial3) {
7120         mip->completeness = 5;
7121       } else if (partial5) {
7122         mip->completeness = 3;
7123       } else if (partial3) {
7124         mip->completeness = 4;
7125       }
7126       vnp = CreateNewDescriptor (psep, Seq_descr_molinfo);
7127       if (vnp != NULL) {
7128         vnp->data.ptrvalue = (Pointer) mip;
7129       }
7130     }
7131     descr = ExtractBioSourceAndPubs (sep);
7132     if (IS_Bioseq_set (sep))
7133     {
7134       topsep = sep;
7135     }
7136     else
7137     {
7138       topsep = GetBestTopParentForData (entityID, sep->data.ptrvalue);
7139     }
7140     AddSeqEntryToSeqEntry (topsep, psep, TRUE);
7141     nsep = FindNucSeqEntry (sep);
7142     ReplaceBioSourceAndPubs (sep, descr);
7143     SetSeqFeatProduct (cds, bsp);
7144     prp = CreateNewProtRef (name_str, NULL, NULL, NULL);
7145     sfp = CreateNewFeature (psep, NULL, SEQFEAT_PROT, NULL);
7146     if (sfp != NULL) {
7147        sfp->data.value.ptrvalue = (Pointer) prp;
7148     }
7149   }
7150   return cds;
7151 
7152 }
7153 
7154 
MakemRNA(SeqLocPtr location,CharPtr protName,SeqEntryPtr sep,Boolean include_utr)7155 static SeqFeatPtr MakemRNA (SeqLocPtr location, CharPtr protName, SeqEntryPtr sep, Boolean include_utr)
7156 {
7157   SeqFeatPtr sfp;
7158   RnaRefPtr  rrp;
7159   Boolean    partial5, partial3;
7160 
7161   sfp = SeqFeatNew();
7162   rrp = RnaRefNew();
7163   rrp->type = RNA_TYPE_mRNA;
7164   rrp->ext.choice = 1;
7165   rrp->ext.value.ptrvalue = protName;
7166   sfp->data.value.ptrvalue = rrp;
7167   sfp->data.choice = SEQFEAT_RNA;
7168 
7169   CheckSeqLocForPartial (location, &partial5, &partial3);
7170   sfp->location = SeqLocFree (sfp->location);
7171   if (include_utr) {
7172     sfp->location = GetmRNALocationFromCDSLocation (location, sfp->idx.entityID);
7173   } else {
7174     sfp->location = AsnIoMemCopy ((Pointer) location,
7175                                   (AsnReadFunc) SeqLocAsnRead,
7176                                   (AsnWriteFunc) SeqLocAsnWrite);
7177   }
7178   sfp->partial = partial5 | partial3;
7179 
7180   return sfp;
7181 }
7182 
7183 
FeatureToCDS(SeqFeatPtr sfp,FeatureToCDSFormPtr fp)7184 static SeqFeatPtr FeatureToCDS (SeqFeatPtr sfp, FeatureToCDSFormPtr fp)
7185 
7186 {
7187   SeqFeatPtr        cds;
7188   SeqMgrFeatContext context;
7189   CharPtr           protName = NULL;
7190   RnaRefPtr         rrp;
7191 
7192 
7193   if (sfp == NULL || fp == NULL || sfp->idx.subtype != fp->featdef_choice)
7194   {
7195     return NULL;
7196   }
7197 
7198   if (fp->makemRNA) {
7199     cds = SeqMgrGetOverlappingmRNA (sfp->location, &context);
7200   } else  {
7201     cds = SeqMgrGetOverlappingCDS (sfp->location, &context);
7202   }
7203   if (cds != NULL)
7204   {
7205     return NULL;
7206   }
7207 
7208   if (SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL,
7209                                0, 0, sfp, &context) == NULL)
7210   {
7211     return NULL;
7212   }
7213 
7214   protName = GetNewProteinName (sfp, fp);
7215   if (protName == NULL)
7216   {
7217     LogFeatureToCDSNoProtein (fp, context.label, SeqLocId (sfp->location));
7218     return NULL;
7219   }
7220 
7221   /* make sure mRNA product name matches CDS protein name */
7222   if (fp->featdef_choice == FEATDEF_mRNA && !fp->makemRNA)
7223   {
7224     rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
7225     if (rrp != NULL)
7226     {
7227       rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
7228       rrp->ext.value.ptrvalue = StringSave (protName);
7229     }
7230   }
7231 
7232   /* need to remove string */
7233   if (fp->featdef_choice == FEATDEF_GENE)
7234   {
7235     RemoveGeneFieldString (sfp, fp->gene_field_list);
7236   }
7237   else if (fp->featdef_choice == FEATDEF_mRNA)
7238   {
7239     RemovemRNAFieldString (sfp, fp->mrna_field_list);
7240   }
7241   else if (fp->featdef_choice == FEATDEF_exon)
7242   {
7243     RemoveExonFieldString (sfp, fp->exon_field_list);
7244   }
7245   else if (fp->featdef_choice == FEATDEF_CDS)
7246   {
7247     RemoveCDSFieldString (sfp, fp->mrna_field_list);
7248   }
7249 
7250   if (fp->makemRNA) {
7251     cds = MakemRNA (sfp->location, protName, fp->sep, fp->include_utr);
7252   } else {
7253     cds = MakeCDS(sfp->location, protName, fp->input_entityID, fp->sep, &(fp->lid));
7254   }
7255 
7256   cds->partial = sfp->partial;
7257   cds->next = sfp->next;
7258   sfp->next = cds;
7259 
7260   return cds;
7261 }
7262 
7263 static void
LogFeatureToCDSMismatchProtein(FeatureToCDSFormPtr fp,SeqIdPtr sip)7264 LogFeatureToCDSMismatchProtein
7265 (FeatureToCDSFormPtr fp,
7266  SeqIdPtr            sip)
7267 {
7268   Char       id [41];
7269 
7270   if (fp == NULL || fp->lid.fp == NULL || sip == NULL) return;
7271 
7272   id [0] = '\0';
7273   SeqIdWrite (SeqIdFindBest (sip, 0), id, PRINTID_FASTA_LONG, sizeof (id) - 1);
7274 
7275   fprintf (fp->lid.fp, "The protein names generated from features on %s do not match\n", id);
7276 
7277   fp->lid.data_in_log = TRUE;
7278 }
7279 
LogCDSAmbiguousFrame(LogInfoPtr lip,SeqFeatPtr sfp)7280 extern void LogCDSAmbiguousFrame (LogInfoPtr lip, SeqFeatPtr sfp)
7281 {
7282   CharPtr loc_str;
7283 
7284   if (lip == NULL || lip->fp == NULL || sfp == NULL) {
7285     return;
7286   }
7287 
7288   loc_str = SeqLocPrintUseBestID (sfp->location);
7289   fprintf (lip->fp, "Ambiguous frames detected for coding region at %s\n", loc_str);
7290   loc_str = MemFree (loc_str);
7291   lip->data_in_log = TRUE;
7292 }
7293 
FeatureToCDSBioseqCheckCallback(BioseqPtr bsp,Pointer userdata)7294 static void FeatureToCDSBioseqCheckCallback (BioseqPtr bsp, Pointer userdata)
7295 
7296 {
7297   FeatureToCDSFormPtr fp;
7298   CharPtr             last_prot_name = NULL, new_prot_name;
7299   SeqMgrFeatContext   feature_context, cds_context;
7300   SeqFeatPtr          sfp, cds;
7301 
7302   if (bsp == NULL || userdata == NULL) return;
7303   fp = (FeatureToCDSFormPtr) userdata;
7304   fp->sep = SeqMgrGetSeqEntryForData (bsp);
7305 
7306   /* if we are fusing features, find all the features on this Bioseq for
7307    * our type.
7308    */
7309   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &feature_context);
7310   while (sfp != NULL)
7311   {
7312     if (sfp->idx.subtype == fp->featdef_choice && DoesObjectMatchConstraintChoiceSet(OBJ_SEQFEAT, sfp, fp->constraint))
7313     {
7314       if (fp->makemRNA) {
7315         cds = SeqMgrGetOverlappingmRNA (sfp->location, &cds_context);
7316       } else {
7317         cds = SeqMgrGetOverlappingCDS (sfp->location, &cds_context);
7318       }
7319       if (cds == NULL)
7320       {
7321         new_prot_name = GetNewProteinName (sfp, fp);
7322         if (!fp->fuse_multiple)
7323         {
7324           if (new_prot_name == NULL)
7325           {
7326             LogFeatureToCDSNoProtein (fp, feature_context.label, SeqLocId (sfp->location));
7327           }
7328         }
7329         else if (last_prot_name == NULL && new_prot_name != NULL)
7330         {
7331           if (new_prot_name == NULL)
7332           {
7333             LogFeatureToCDSNoProtein (fp, feature_context.label, SeqLocId (sfp->location));
7334           }
7335           else
7336           {
7337             last_prot_name = new_prot_name;
7338           }
7339         }
7340         else if (new_prot_name == NULL)
7341         {
7342           /* do nothing - will use protein name from prior CDS */
7343         }
7344         else if (StringCmp (last_prot_name, new_prot_name) == 0)
7345         {
7346           /* no conflict */
7347           MemFree (new_prot_name);
7348         }
7349         else
7350         {
7351           LogFeatureToCDSMismatchProtein (fp, SeqLocId (sfp->location));
7352           MemFree (last_prot_name);
7353           last_prot_name = new_prot_name;
7354         }
7355       }
7356     }
7357     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, fp->featdef_choice, &feature_context);
7358   }
7359 }
7360 
FeatureToCDSBioseqActCallback(BioseqPtr bsp,Pointer userdata)7361 static void FeatureToCDSBioseqActCallback (BioseqPtr bsp, Pointer userdata)
7362 
7363 {
7364   FeatureToCDSFormPtr fp;
7365   SeqFeatPtr          first = NULL;
7366   CharPtr             new_prot_name;
7367   SeqMgrFeatContext   feature_context, cds_context;
7368   SeqFeatPtr          sfp, cds;
7369   SeqLocPtr           new_cds_location = NULL, slp, tmp_loc;
7370   Boolean             first_partial5, first_partial3;
7371   Int4                first_start_pos, first_stop_pos;
7372   Boolean             sfp_partial5, sfp_partial3;
7373   Int4                sfp_start_pos, sfp_stop_pos;
7374 
7375   if (bsp == NULL || userdata == NULL) return;
7376   fp = (FeatureToCDSFormPtr) userdata;
7377   fp->sep = SeqMgrGetSeqEntryForData (bsp);
7378 
7379   /* if we are fusing features, find all the features on this Bioseq for
7380    * our type.
7381    */
7382   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &feature_context);
7383   while (sfp != NULL)
7384   {
7385     if (sfp->idx.subtype == fp->featdef_choice && DoesObjectMatchConstraintChoiceSet (OBJ_SEQFEAT, sfp, fp->constraint))
7386     {
7387       if (fp->makemRNA) {
7388         cds = SeqMgrGetOverlappingmRNA (sfp->location, &cds_context);
7389       } else {
7390         cds = SeqMgrGetOverlappingCDS (sfp->location, &cds_context);
7391       }
7392       if (cds == NULL)
7393       {
7394         if (fp->fuse_multiple)
7395         {
7396           if (first == NULL)
7397           {
7398             new_prot_name = GetNewProteinName (sfp, fp);
7399             if (new_prot_name != NULL)
7400             {
7401               first = sfp;
7402               new_cds_location = (SeqLocPtr) AsnIoMemCopy ((Pointer) sfp->location,
7403                                                      (AsnReadFunc) SeqLocAsnRead,
7404                                                      (AsnWriteFunc) SeqLocAsnWrite);
7405               MemFree (new_prot_name);
7406             }
7407           }
7408           else
7409           {
7410             /* preserve partialness of ends */
7411             CheckSeqLocForPartial (new_cds_location, &first_partial5, &first_partial3);
7412             first_start_pos = SeqLocStart (new_cds_location);
7413             first_stop_pos = SeqLocStop (new_cds_location);
7414             CheckSeqLocForPartial (sfp->location, &sfp_partial5, &sfp_partial3);
7415             sfp_start_pos = SeqLocStart (sfp->location);
7416             sfp_stop_pos = SeqLocStop (sfp->location);
7417             if (first_start_pos > sfp_start_pos)
7418             {
7419               first_partial5 = sfp_partial5;
7420             }
7421             if (first_stop_pos < sfp_stop_pos)
7422             {
7423               first_partial3 = sfp_partial3;
7424             }
7425 
7426             slp = SeqLocMerge (bsp, sfp->location, new_cds_location, FALSE, TRUE, FALSE);
7427             new_cds_location = SeqLocFree (new_cds_location);
7428             new_cds_location = slp;
7429             SetSeqLocPartial (new_cds_location, first_partial5, first_partial3);
7430             first_start_pos = SeqLocStart (new_cds_location);
7431             first_stop_pos = SeqLocStop (new_cds_location);
7432           }
7433         }
7434         else
7435         {
7436           FeatureToCDS (sfp, fp);
7437         }
7438       }
7439     }
7440     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, fp->featdef_choice, &feature_context);
7441   }
7442   if (fp->fuse_multiple && first != NULL)
7443   {
7444     tmp_loc = first->location;
7445     first->location = new_cds_location;
7446     cds = FeatureToCDS (first, fp);
7447     if (cds != NULL)
7448     {
7449       cds->partial = CheckSeqLocForPartial (cds->location, &first_partial5, &first_partial3);
7450     }
7451     first->location = tmp_loc;
7452     new_cds_location = SeqLocFree (new_cds_location);
7453   }
7454 }
7455 
FeatureToCDSAccept(ButtoN b)7456 static void FeatureToCDSAccept (ButtoN b)
7457 {
7458   FeatureToCDSFormPtr    fp;
7459   Int4                   feature_choice;
7460   MsgAnswer              ans = ANS_YES;
7461 
7462   fp = (FeatureToCDSFormPtr) GetObjectExtra (b);
7463   if (fp == NULL)
7464   {
7465     return;
7466   }
7467 
7468   feature_choice = GetValue (fp->feature_choice);
7469   switch (feature_choice)
7470   {
7471     case FEATURE_TO_CDS_GENE:
7472       fp->featdef_choice = FEATDEF_GENE;
7473       fp->gene_field_list = DialogToPointer (fp->gene_field);
7474       break;
7475     case FEATURE_TO_CDS_MRNA:
7476       if (fp->makemRNA) {
7477         fp->featdef_choice = FEATDEF_CDS;
7478       } else {
7479         fp->featdef_choice = FEATDEF_mRNA;
7480       }
7481       fp->mrna_field_list = DialogToPointer (fp->mrna_field);
7482       break;
7483     case FEATURE_TO_CDS_EXON:
7484       fp->featdef_choice = FEATDEF_exon;
7485       fp->exon_field_list = DialogToPointer (fp->exon_field);
7486       break;
7487     case FEATURE_TO_CDS_5UTR:
7488       fp->featdef_choice = FEATDEF_5UTR;
7489       break;
7490     case FEATURE_TO_CDS_3UTR:
7491       fp->featdef_choice = FEATDEF_3UTR;
7492       break;
7493     default:
7494       return;
7495   }
7496 
7497   TmpNam (fp->lid.path);
7498   fp->lid.fp = FileOpen (fp->lid.path, "wb");
7499   if (fp->lid.fp == NULL) return;
7500   fp->lid.display_title = "Name Problems";
7501 
7502   Hide (fp->form);
7503   WatchCursor ();
7504   Update ();
7505 
7506   fp->sep = GetTopSeqEntryForEntityID (fp->input_entityID);
7507   if (fp->sep == NULL) return;
7508 
7509   fp->caps_choice = GetValue (fp->qual_caps_grp);
7510 
7511   fp->append_string = JustSaveStringFromText (fp->append_text);
7512 
7513   fp->fuse_multiple = GetStatus (fp->fuse_multiple_btn);
7514   if (fp->makemRNA) {
7515     fp->include_utr = GetStatus (fp->include_utr_btn);
7516   }
7517 
7518   fp->constraint = DialogToPointer (fp->constraint_dlg);
7519   VisitBioseqsInSep (fp->sep, (Pointer) fp, FeatureToCDSBioseqCheckCallback);
7520 
7521   if (ans == ANS_YES)
7522   {
7523     fp->sep = GetTopSeqEntryForEntityID (fp->input_entityID);
7524     VisitBioseqsInSep (fp->sep, (Pointer) fp, FeatureToCDSBioseqActCallback);
7525   }
7526   fp->constraint = ConstraintChoiceSetFree(fp->constraint);
7527 
7528   CloseLog (&(fp->lid));
7529 
7530   ArrowCursor ();
7531   Update ();
7532 
7533   ObjMgrSetDirtyFlag (fp->input_entityID, TRUE);
7534   ObjMgrSendMsg (OM_MSG_UPDATE, fp->input_entityID, 0, 0);
7535   if (GetStatus (fp->leave_dlg_up)) {
7536     Show (fp->form);
7537   } else {
7538     Remove (fp->form);
7539   }
7540 }
7541 
FeatureToCDSormRNA(IteM i,Boolean makemRNA)7542 static void FeatureToCDSormRNA (IteM i, Boolean makemRNA)
7543 
7544 {
7545   BaseFormPtr            bfp;
7546   FeatureToCDSFormPtr    fp;
7547   WindoW                 w;
7548   GrouP                  h, m, g, c;
7549   CharPtr                title, grp_title;
7550 
7551 #ifdef WIN_MAC
7552   bfp = currentFormDataPtr;
7553 #else
7554   bfp = GetObjectExtra (i);
7555 #endif
7556   if (bfp == NULL) {
7557     Message (MSG_ERROR, "FeatureToCDS error");
7558     return;
7559   }
7560 
7561   fp = (FeatureToCDSFormPtr) MemNew (sizeof (FeatureToCDSFormData));
7562   if (fp == NULL) return;
7563   fp->input_entityID = bfp->input_entityID;
7564   fp->input_itemID = bfp->input_itemID;
7565   fp->input_itemtype = bfp->input_itemtype;
7566 
7567   fp->makemRNA = makemRNA;
7568 
7569   if (makemRNA) {
7570     title = "Feature to mRNA";
7571   } else {
7572     title = "Feature to CDS";
7573   }
7574   w = FixedWindow (-50, -33, -10, -10, title, StdCloseWindowProc);
7575   SetObjectExtra (w, fp, CleanupFeatureToCDSPage);
7576   fp->form = (ForM) w;
7577 
7578   h = HiddenGroup (w, -1, 0, NULL);
7579   SetGroupSpacing (h, 10, 10);
7580 
7581   fp->feature_choice = PopupList (h, TRUE, ChangeFeatureToCDS);
7582   PopupItem (fp->feature_choice, "Gene");
7583   if (makemRNA) {
7584     PopupItem (fp->feature_choice, "CDS");
7585   } else {
7586     PopupItem (fp->feature_choice, "mRNA");
7587   }
7588   PopupItem (fp->feature_choice, "exon");
7589   if (makemRNA) {
7590     PopupItem (fp->feature_choice, "5' UTR");
7591     PopupItem (fp->feature_choice, "3' UTR");
7592   }
7593   SetValue (fp->feature_choice, FEATURE_TO_CDS_GENE);
7594   SetObjectExtra (fp->feature_choice, fp, NULL);
7595 
7596   if (makemRNA) {
7597     grp_title = "Source for new mRNA name";
7598   } else {
7599     grp_title = "Source for new CDS protein name";
7600   }
7601   fp->name_choice_grp = HiddenGroup (h, -1, 0, NULL);
7602   SetGroupSpacing (fp->name_choice_grp, 10, 10);
7603   g = NormalGroup (fp->name_choice_grp, 0, 0, grp_title, NULL, NULL);
7604   fp->gene_field = FeatureFieldChoiceDialog (g, GeneFieldSelectionDialog, TRUE, EnableFeatureToCDSControls, fp);
7605   fp->mrna_field = FeatureFieldChoiceDialog (g, MRNAFieldSelectionDialog, TRUE, EnableFeatureToCDSControls, fp);
7606   fp->exon_field = FeatureFieldChoiceDialog (g, ExonFieldSelectionDialog, TRUE, EnableFeatureToCDSControls, fp);
7607   Hide (fp->mrna_field);
7608   Hide (fp->exon_field);
7609   AlignObjects (ALIGN_CENTER, (HANDLE) fp->gene_field,
7610                               (HANDLE) fp->mrna_field,
7611                               (HANDLE) fp->exon_field,
7612                               NULL);
7613 
7614   fp->qual_caps_grp = NormalGroup (fp->name_choice_grp, 3, 0,
7615                      "Capitalization for field in name", NULL, NULL);
7616   RadioButton (fp->qual_caps_grp, "As is");
7617   RadioButton (fp->qual_caps_grp, "Capitalize first initial");
7618   RadioButton (fp->qual_caps_grp, "Capitalize all");
7619   SetValue (fp->qual_caps_grp, 1);
7620   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) fp->qual_caps_grp, NULL);
7621 
7622   m = HiddenGroup (h, 0, 2, NULL);
7623   StaticPrompt (m, "Append text to name", 0, 0, programFont, 'c');
7624   fp->append_text = DialogText (m, "", 14, EnableFeatureToCDSControlsText);
7625   SetObjectExtra (fp->append_text, fp, NULL);
7626 
7627   if(makemRNA) {
7628     fp->fuse_multiple_btn = CheckBox (h, "Fuse multiple intervals for new mRNA", NULL);
7629     fp->include_utr_btn = CheckBox (h, "Include UTR regions in mRNA location", NULL);
7630   } else {
7631     fp->fuse_multiple_btn = CheckBox (h, "Fuse multiple intervals for new CDS", NULL);
7632     fp->include_utr_btn = NULL;
7633   }
7634 
7635   fp->constraint_dlg = ComplexConstraintDialog(h, NULL, NULL);
7636   ChangeComplexConstraintFieldType (fp->constraint_dlg, FieldType_cds_gene_prot, NULL, Macro_feature_type_gene);
7637 
7638   c = HiddenGroup (h, 4, 0, NULL);
7639   fp->accept_btn = PushButton (c, "Accept", FeatureToCDSAccept);
7640   SetObjectExtra (fp->accept_btn, fp, NULL);
7641   EnableFeatureToCDSControls (fp);
7642 
7643   PushButton (c, "Cancel", StdCancelButtonProc);
7644   fp->leave_dlg_up = CheckBox (c, "Leave Dialog Up", NULL);
7645 
7646   AlignObjects (ALIGN_CENTER, (HANDLE) fp->feature_choice,
7647                               (HANDLE) fp->name_choice_grp,
7648                               (HANDLE) m,
7649                               (HANDLE) fp->fuse_multiple_btn,
7650                               (HANDLE) fp->constraint_dlg,
7651                               (HANDLE) c,
7652                               (HANDLE) fp->include_utr_btn,
7653                               NULL);
7654 
7655   RealizeWindow (w);
7656   Show (w);
7657   Update ();
7658 
7659 }
7660 
FeatureToCds(IteM i)7661 static void FeatureToCds (IteM i)
7662 {
7663   FeatureToCDSormRNA (i, FALSE);
7664 }
7665 
7666 
FeatureTomRNA(IteM i)7667 static void FeatureTomRNA (IteM i)
7668 {
7669   FeatureToCDSormRNA (i, TRUE);
7670 }
7671 
7672 
AddFeatureToBioseq(SeqFeatPtr sfp,BioseqPtr bsp)7673 static void AddFeatureToBioseq (SeqFeatPtr sfp, BioseqPtr bsp)
7674 
7675 {
7676   SeqFeatPtr   prev;
7677   SeqAnnotPtr  sap;
7678 
7679   if (sfp == NULL || bsp == NULL) return;
7680   sap = bsp->annot;
7681   while (sap != NULL && (sap->name != NULL || sap->desc != NULL || sap->type != 1)) {
7682     sap = sap->next;
7683   }
7684   if (sap == NULL) {
7685     sap = SeqAnnotNew ();
7686     if (sap != NULL) {
7687       sap->type = 1;
7688       sap->next = bsp->annot;
7689       bsp->annot = sap;
7690     }
7691   }
7692   sap = bsp->annot;
7693   if (sap != NULL) {
7694     if (sap->data != NULL) {
7695       prev = sap->data;
7696       while (prev->next != NULL) {
7697         prev = prev->next;
7698       }
7699       prev->next = sfp;
7700     } else {
7701       sap->data = (Pointer) sfp;
7702     }
7703   }
7704 }
7705 
PackageFeatureCallback(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)7706 static void PackageFeatureCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
7707 
7708 {
7709   BaseFormPtr    bfp;
7710   BioseqPtr      bsp = NULL;
7711   BioseqSetPtr   bssp = NULL;
7712   SeqAnnotPtr    nextsap;
7713   SeqFeatPtr     nextsfp;
7714   Pointer PNTR   prevsap;
7715   Pointer PNTR   prevsfp;
7716   SeqAnnotPtr    sap;
7717   SeqFeatPtr     sfp;
7718   BioseqPtr      target;
7719 
7720   if (sep == NULL || sep->data.ptrvalue == NULL) return;
7721   bfp = (BaseFormPtr) mydata;
7722   if (bfp == NULL) return;
7723   if (IS_Bioseq (sep)) {
7724     bsp = (BioseqPtr) sep->data.ptrvalue;
7725     sap = bsp->annot;
7726     prevsap = (Pointer PNTR) &(bsp->annot);
7727   } else if (IS_Bioseq_set (sep)) {
7728     bssp = (BioseqSetPtr) sep->data.ptrvalue;
7729     sap = bssp->annot;
7730     prevsap = (Pointer PNTR) &(bssp->annot);
7731   } else return;
7732   while (sap != NULL) {
7733     nextsap = sap->next;
7734     if (sap->type == 1) {
7735       sfp = (SeqFeatPtr) sap->data;
7736       prevsfp = (Pointer PNTR) &(sap->data);
7737       while (sfp != NULL) {
7738         nextsfp = sfp->next;
7739         target = GetBioseqGivenSeqLoc (sfp->location, bfp->input_entityID);
7740         if (target != bsp) {
7741           *(prevsfp) = sfp->next;
7742           sfp->next = NULL;
7743           AddFeatureToBioseq (sfp, target);
7744         } else {
7745           prevsfp = (Pointer PNTR) &(sfp->next);
7746         }
7747         sfp = nextsfp;
7748       }
7749     }
7750     if (sap->data == NULL) {
7751       *(prevsap) = sap->next;
7752       sap->next = NULL;
7753       SeqAnnotFree (sap);
7754     } else {
7755       prevsap = (Pointer PNTR) &(sap->next);
7756     }
7757     sap = nextsap;
7758   }
7759 }
7760 
PackageOnParts(IteM i)7761 static void PackageOnParts (IteM i)
7762 
7763 {
7764   BaseFormPtr  bfp;
7765   SeqEntryPtr  sep;
7766 
7767 #ifdef WIN_MAC
7768   bfp = currentFormDataPtr;
7769 #else
7770   bfp = GetObjectExtra (i);
7771 #endif
7772   if (bfp == NULL) return;
7773   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
7774   if (sep == NULL) return;
7775   WatchCursor ();
7776   Update ();
7777   SeqEntryExplore (sep, bfp, PackageFeatureCallback);
7778   ArrowCursor ();
7779   Update ();
7780   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
7781   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
7782 }
7783 
7784 
GetParentNPS(BioseqPtr bsp)7785 static BioseqSetPtr GetParentNPS (BioseqPtr bsp)
7786 {
7787   BioseqSetPtr  bssp;
7788 
7789   if (bsp == NULL) return NULL;
7790   if (bsp->idx.parenttype != OBJ_BIOSEQSET) return NULL;
7791   bssp = (BioseqSetPtr) bsp->idx.parentptr;
7792   while (bssp != NULL && bssp->_class != BioseqseqSet_class_nuc_prot && bssp->idx.parenttype == OBJ_BIOSEQSET) {
7793     bssp = (BioseqSetPtr) bssp->idx.parentptr;
7794   }
7795   if (bssp != NULL && bssp->_class == BioseqseqSet_class_nuc_prot) return bssp;
7796   return NULL;
7797 }
7798 
NucAndProtNotInSameNPS(BioseqPtr nuc,BioseqPtr prt)7799 static Boolean NucAndProtNotInSameNPS (BioseqPtr nuc, BioseqPtr prt)
7800 {
7801   BioseqSetPtr    bssp;
7802 
7803   if (nuc == NULL || prt == NULL) return FALSE;
7804   bssp = GetParentNPS (nuc);
7805   if (bssp == NULL) return TRUE;
7806   if (GetParentNPS (prt) != bssp) return TRUE;
7807   return FALSE;
7808 }
7809 
7810 typedef struct nppack {
7811   BioseqPtr  nuc;
7812   BioseqPtr  prt;
7813 } NpPack, PNTR NpPackPtr;
7814 
PackageProteinsCallback(SeqFeatPtr sfp,Pointer userdata)7815 static void PackageProteinsCallback (SeqFeatPtr sfp, Pointer userdata)
7816 
7817 {
7818   BioseqSetPtr       bssp;
7819   SeqMgrDescContext  context;
7820   ValNodePtr PNTR    headp;
7821   MolInfoPtr         mip;
7822   NpPackPtr          npp;
7823   BioseqPtr          nuc, prt;
7824   SeqDescrPtr        sdp;
7825 
7826   if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION || sfp->product == NULL) return;
7827   nuc = BioseqFindFromSeqLoc (sfp->location);
7828   prt = BioseqFindFromSeqLoc (sfp->product);
7829   if (nuc == NULL || prt == NULL) return;
7830 
7831   headp = (ValNodePtr PNTR) userdata;
7832 
7833   /* if CDS location is on genomic nucleotide in genomic product set, bail */
7834 
7835   if (nuc->idx.parenttype == OBJ_BIOSEQSET) {
7836     bssp = (BioseqSetPtr) nuc->idx.parentptr;
7837     if (bssp != NULL && bssp->_class == BioseqseqSet_class_gen_prod_set) {
7838       sdp = SeqMgrGetNextDescriptor (nuc, NULL, Seq_descr_molinfo, &context);
7839       if (sdp != NULL) {
7840         mip = (MolInfoPtr) sdp->data.ptrvalue;
7841         if (mip != NULL) {
7842           if (mip->biomol != MOLECULE_TYPE_MRNA) return;
7843         }
7844       }
7845     }
7846   }
7847 
7848   if (NucAndProtNotInSameNPS (nuc, prt)) {
7849     npp = (NpPackPtr) MemNew (sizeof (NpPack));
7850     if (npp == NULL) return;
7851     npp->nuc = nuc;
7852     npp->prt = (BioseqPtr) AsnIoMemCopy ((Pointer) prt,
7853                                          (AsnReadFunc) BioseqAsnRead,
7854                                          (AsnWriteFunc) BioseqAsnWrite);
7855     ValNodeAddPointer (headp, 0, (Pointer) npp);
7856     prt->idx.deleteme = TRUE;
7857   }
7858 }
7859 
PackageOnNucs(IteM i)7860 static void PackageOnNucs (IteM i)
7861 
7862 {
7863   BaseFormPtr    bfp;
7864   ValNodePtr     descr;
7865   ValNodePtr     head = NULL, vnp;
7866   NpPackPtr      npp;
7867   BioseqSetPtr   nps;
7868   SeqEntryPtr    nsep, psep;
7869   BioseqPtr      nuc, prt;
7870   SeqEntryPtr    sep;
7871 
7872 #ifdef WIN_MAC
7873   bfp = currentFormDataPtr;
7874 #else
7875   bfp = GetObjectExtra (i);
7876 #endif
7877   if (bfp == NULL) return;
7878   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
7879   if (sep == NULL) return;
7880   WatchCursor ();
7881   Update ();
7882 
7883   VisitFeaturesInSep (sep, &head, PackageProteinsCallback);
7884 
7885   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
7886   SeqMgrClearFeatureIndexes (bfp->input_entityID, NULL);
7887 
7888   for (vnp = head; vnp != NULL; vnp = vnp->next) {
7889     npp = (NpPackPtr) vnp->data.ptrvalue;
7890     if (npp == NULL) continue;
7891     nuc = npp->nuc;
7892     prt = npp->prt;
7893     if (nuc == NULL || prt == NULL) continue;
7894     nsep = nuc->seqentry;
7895     nps = GetParentNPS (nuc);
7896     if (nps != NULL) {
7897       nsep = nps->seqentry;
7898     }
7899     psep = SeqEntryNew ();
7900     if (nsep == NULL || psep == NULL) continue;
7901     psep->choice = 1;
7902     psep->data.ptrvalue = (Pointer) prt;
7903     SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) prt, psep);
7904     descr = ExtractBioSourceAndPubs (nsep);
7905     AddSeqEntryToSeqEntry (nsep, psep, TRUE);
7906     ReplaceBioSourceAndPubs (nsep, descr);
7907     AssignIDsInEntity (bfp->input_entityID, 0, NULL);
7908   }
7909   ValNodeFreeData (head);
7910 
7911   ArrowCursor ();
7912   Update ();
7913   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
7914   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
7915 }
7916 
7917 extern EnumFieldAssoc  enum_bond_alist [];
7918 extern EnumFieldAssoc  enum_site_alist [];
7919 
7920 static Boolean            alistBoxUp;
7921 static Boolean            alistBoxAccept;
7922 static PopuP              alistBoxPopup;
7923 
AcceptAlistMessage(ButtoN b)7924 static void AcceptAlistMessage (ButtoN b)
7925 
7926 {
7927   alistBoxAccept = TRUE;
7928   alistBoxUp = FALSE;
7929 }
7930 
CancelAlistMessage(ButtoN b)7931 static void CancelAlistMessage (ButtoN b)
7932 
7933 {
7934   alistBoxAccept = FALSE;
7935   alistBoxUp = FALSE;
7936 }
7937 
AlistMessage(EnumFieldAssocPtr al,UIEnumPtr val,UIEnum dflt,CharPtr mssg)7938 extern Boolean AlistMessage (EnumFieldAssocPtr al, UIEnumPtr val, UIEnum dflt, CharPtr mssg)
7939 
7940 {
7941   GrouP   c;
7942   GrouP   g;
7943   PrompT  ppt;
7944   WindoW  w;
7945 
7946   if (al == NULL || val == NULL) return FALSE;
7947   alistBoxUp = TRUE;
7948   alistBoxAccept = FALSE;
7949   w = ModalWindow (-50, -20, -20, -20, NULL);
7950   if (w != NULL) {
7951     g = HiddenGroup (w, -1, 0, NULL);
7952     SetGroupSpacing (g, 10, 10);
7953     ppt = StaticPrompt (g, mssg, 0, 0, programFont, 'c');
7954     alistBoxPopup = PopupList (g, TRUE, NULL);
7955     InitEnumPopup (alistBoxPopup, al, NULL);
7956     SetEnumPopup (alistBoxPopup, al, dflt);
7957     c = HiddenGroup (g, 2, 0, NULL);
7958     DefaultButton (c, "Accept", AcceptAlistMessage);
7959     PushButton (c, "Cancel", CancelAlistMessage);
7960     AlignObjects (ALIGN_CENTER, (HANDLE) ppt, (HANDLE) alistBoxPopup, (HANDLE) c, NULL);
7961     RealizeWindow (w);
7962     Show (w);
7963     Select (w);
7964     while (alistBoxUp) {
7965       ProcessExternalEvent ();
7966       Update ();
7967     }
7968     ProcessAnEvent ();
7969     if (! GetEnumPopup (alistBoxPopup, al, val)) {
7970       alistBoxAccept = FALSE;
7971     }
7972     Remove (w);
7973   }
7974   return alistBoxAccept;
7975 }
7976 
7977 
7978 
UnlinkPubDesc(GatherContextPtr gcp)7979 static Boolean UnlinkPubDesc (GatherContextPtr gcp)
7980 
7981 {
7982   ValNodePtr       sdp;
7983   ValNodePtr PNTR  vnpp;
7984 
7985   if (gcp->thistype != OBJ_SEQDESC) return TRUE;
7986   sdp = (ValNodePtr) gcp->thisitem;
7987   if (sdp == NULL || sdp->choice != Seq_descr_pub) return TRUE;
7988   vnpp = (ValNodePtr PNTR) gcp->userdata;
7989   if (vnpp == NULL) return TRUE;
7990   *(gcp->prevlink) = sdp->next;
7991   sdp->next = NULL;
7992   *vnpp = sdp;
7993   return TRUE;
7994 }
7995 
AddConvertedDescFeat(SeqEntryPtr sep,ValNodePtr vnp)7996 static void AddConvertedDescFeat (SeqEntryPtr sep, ValNodePtr vnp)
7997 {
7998   BioseqSetPtr  bssp;
7999   BioseqPtr     bsp;
8000   SeqFeatPtr    sfp;
8001 
8002   if (sep == NULL || vnp == NULL) return;
8003   if (IS_Bioseq_set (sep)) {
8004     bssp = (BioseqSetPtr) sep->data.ptrvalue;
8005 	for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
8006       AddConvertedDescFeat (sep, vnp);
8007 	}
8008   } else {
8009     bsp = (BioseqPtr) sep->data.ptrvalue;
8010     if (ISA_aa (bsp->mol)) return;
8011     sfp = CreateNewFeature (sep, NULL, SEQFEAT_PUB, NULL);
8012     if (sfp != NULL) {
8013       sfp->data.value.ptrvalue = AsnIoMemCopy ((Pointer) vnp->data.ptrvalue,
8014                                                (AsnReadFunc) PubdescAsnRead,
8015                                                (AsnWriteFunc) PubdescAsnWrite);
8016     }
8017   }
8018 }
8019 
CommonConvertDescToFeat(BaseFormPtr bfp,Boolean pub,Boolean src,Boolean com,CharPtr findstring)8020 static void CommonConvertDescToFeat (BaseFormPtr bfp, Boolean pub, Boolean src, Boolean com, CharPtr findstring)
8021 
8022 {
8023   SeqEntryPtr   sep;
8024   SelStructPtr  sel;
8025   ValNodePtr    vnp;
8026   Boolean       asked_about_prop = FALSE;
8027   Boolean       propagate_descriptors = FALSE;
8028 
8029   if (bfp == NULL) return;
8030   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
8031   if (sep == NULL) return;
8032   sel = ObjMgrGetSelected ();
8033   if (pub && sel != NULL) {
8034     if (sel->entityID == bfp->input_entityID &&
8035         sel->next == NULL && sel->itemtype == OBJ_SEQDESC) {
8036       vnp = NULL;
8037       sep = GetBestTopParentForItemID (sel->entityID, sel->itemID, sel->itemtype);
8038       if (sep != NULL) {
8039         /* unlink changes itemID, so sep must be determined first */
8040         GatherItem (sel->entityID, sel->itemID, sel->itemtype, (Pointer) &vnp, UnlinkPubDesc);
8041         if (vnp != NULL) {
8042           AddConvertedDescFeat (sep, vnp);
8043           ValNodeFree (vnp);
8044         }
8045       }
8046     }
8047     ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
8048     ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
8049     return;
8050   }
8051   if (ConvertPubSrcComDescsToFeats (sep, pub, src, com, FALSE, &asked_about_prop, &propagate_descriptors, findstring)) {
8052     ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
8053     ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
8054   }
8055 }
8056 
8057 
CommonConvertDescToFeatMenuItem(IteM i,Boolean pub,Boolean src,Boolean com)8058 static void CommonConvertDescToFeatMenuItem (IteM i, Boolean pub, Boolean src, Boolean com)
8059 {
8060   BaseFormPtr   bfp;
8061 
8062 #ifdef WIN_MAC
8063   bfp = currentFormDataPtr;
8064 #else
8065   bfp = GetObjectExtra (i);
8066 #endif
8067   if (bfp == NULL) return;
8068   CommonConvertDescToFeat (bfp, pub, src, com, NULL);
8069 }
8070 
ConvertPubDescToFeat(IteM i)8071 static void ConvertPubDescToFeat (IteM i)
8072 
8073 {
8074   CommonConvertDescToFeatMenuItem (i, TRUE, FALSE, FALSE);
8075 }
8076 
ConvertSrcDescToFeat(IteM i)8077 static void ConvertSrcDescToFeat (IteM i)
8078 
8079 {
8080   CommonConvertDescToFeatMenuItem (i, FALSE, TRUE, FALSE);
8081 }
8082 
ConvertComDescToFeat(IteM i)8083 static void ConvertComDescToFeat (IteM i)
8084 
8085 {
8086   CommonConvertDescToFeatMenuItem (i, FALSE, FALSE, TRUE);
8087 }
8088 
8089 typedef struct convertpubdescdata {
8090   DESCRIPTOR_FORM_BLOCK
8091   BaseFormPtr bfp;
8092   TexT    findthis;
8093   Char    findString [255];
8094 } ConvertPubDescData, PNTR ConvertPubDescPtr;
8095 
8096 
DoConvertPubDescStringConstraint(ButtoN b)8097 static void DoConvertPubDescStringConstraint (ButtoN b)
8098 {
8099   ConvertPubDescPtr cpdp;
8100 
8101   cpdp = (ConvertPubDescPtr) GetObjectExtra (b);
8102   if (cpdp == NULL) return;
8103   Hide (cpdp->form);
8104 
8105   GetTitle (cpdp->findthis, cpdp->findString, sizeof (cpdp->findString) - 1);
8106   if (StringHasNoText (cpdp->findString)) {
8107     CommonConvertDescToFeat (cpdp->bfp, TRUE, FALSE, FALSE, NULL);
8108   } else {
8109 	CommonConvertDescToFeat (cpdp->bfp, TRUE, FALSE, FALSE, cpdp->findString);
8110   }
8111 
8112   ObjMgrSetDirtyFlag (cpdp->input_entityID, TRUE);
8113   ObjMgrSendMsg (OM_MSG_UPDATE, cpdp->input_entityID, 0, 0);
8114   Remove (cpdp->form);
8115 }
8116 
CreateConvertPubDescStringConstraintDialogX(IteM i)8117 static void CreateConvertPubDescStringConstraintDialogX (IteM i)
8118 {
8119   BaseFormPtr       bfp;
8120   ConvertPubDescPtr cpdp;
8121   WindoW            w;
8122   GrouP             h, g, c;
8123   ButtoN            b;
8124 
8125 #ifdef WIN_MAC
8126   bfp = currentFormDataPtr;
8127 #else
8128   bfp = GetObjectExtra (i);
8129 #endif
8130   if (bfp == NULL) return;
8131 
8132   cpdp = (ConvertPubDescPtr) MemNew (sizeof (ConvertPubDescData));
8133   if (cpdp == NULL) return;
8134   cpdp->bfp = bfp;
8135 
8136   w = FixedWindow (-50, -33, -10, -10, "Convert Pub Descriptors", StdCloseWindowProc);
8137   SetObjectExtra (w, cpdp, StdCleanupFormProc);
8138   cpdp->form = (ForM) w;
8139   cpdp->formmessage = NULL;
8140 
8141   cpdp->input_entityID = bfp->input_entityID;
8142 
8143   h = HiddenGroup (w, 0, 2, NULL);
8144   g = HiddenGroup (h, 2, 0, NULL);
8145   StaticPrompt (g, "Optional string constraint", 0, dialogTextHeight, programFont, 'c');
8146   cpdp->findthis = DialogText (g, "", 14, NULL);
8147 
8148   c = HiddenGroup (h, 2, 0, NULL);
8149   b = DefaultButton (c, "Accept", DoConvertPubDescStringConstraint);
8150   SetObjectExtra (b, cpdp, NULL);
8151   PushButton (c, "Cancel", StdCancelButtonProc);
8152 
8153   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
8154   RealizeWindow (w);
8155   Show (w);
8156   Update ();
8157 }
8158 
8159 
8160 typedef struct feattodesc {
8161   Boolean pub;
8162   Boolean src;
8163   Boolean com;
8164 } FeatToDescData, PNTR FeatToDescPtr;
8165 
ConvertOneFeatToDesc(SeqFeatPtr sfp,Pointer userdata)8166 static void ConvertOneFeatToDesc (SeqFeatPtr sfp, Pointer userdata)
8167 {
8168   SeqDescPtr sdp;
8169   SeqEntryPtr sep;
8170   SeqIdPtr    sip;
8171   BioseqPtr   bsp;
8172   ValNode     vn;
8173   FeatToDescPtr fdp;
8174   BioSourcePtr  biop;
8175   SubSourcePtr  ssp, last_ssp = NULL;
8176   CharPtr       new_note;
8177 
8178   if (sfp == NULL || (fdp = (FeatToDescPtr) userdata) == NULL
8179       || (sfp->data.choice == SEQFEAT_PUB && !fdp->pub)
8180       || (sfp->data.choice == SEQFEAT_BIOSRC && !fdp->src)
8181       || (sfp->data.choice == SEQFEAT_COMMENT && !fdp->com)
8182       || (sfp->data.choice != SEQFEAT_PUB
8183           && sfp->data.choice != SEQFEAT_BIOSRC
8184           && sfp->data.choice != SEQFEAT_COMMENT)) {
8185     return;
8186   }
8187 
8188   /* perform only if feature is full-length */
8189   sip = SeqLocId (sfp->location);
8190   bsp = BioseqFind (sip);
8191   if (bsp == NULL) return;
8192   sip = SeqIdFindBest(bsp->id, 0);
8193   if (sip == NULL) return;
8194   vn.choice = SEQLOC_WHOLE;
8195   vn.extended = 0;
8196   vn.data.ptrvalue = (Pointer) sip;
8197   vn.next = NULL;
8198   /* is feature full length? */
8199   if (SeqLocCompare (sfp->location, &vn) != SLC_A_EQ_B) return;
8200 
8201   sep = GetBestTopParentForItemID (sfp->idx.entityID, sfp->idx.itemID, OBJ_SEQFEAT);
8202   if (sep == NULL) return;
8203 
8204   if (sfp->data.choice == SEQFEAT_PUB) {
8205     sdp = CreateNewDescriptor (sep, Seq_descr_pub);
8206     sdp->data.ptrvalue = AsnIoMemCopy ((Pointer) sfp->data.value.ptrvalue,
8207                                        (AsnReadFunc) PubdescAsnRead,
8208                                        (AsnWriteFunc) PubdescAsnWrite);
8209   } else if (sfp->data.choice == SEQFEAT_BIOSRC) {
8210     sdp = CreateNewDescriptor (sep, Seq_descr_source);
8211     sdp->data.ptrvalue = AsnIoMemCopy ((Pointer) sfp->data.value.ptrvalue,
8212                                        (AsnReadFunc) BioSourceAsnRead,
8213                                        (AsnWriteFunc) BioSourceAsnWrite);
8214     if (!StringHasNoText (sfp->comment)) {
8215       biop = (BioSourcePtr) sdp->data.ptrvalue;
8216       ssp = biop->subtype;
8217       while (ssp != NULL && ssp->subtype != 255) {
8218         last_ssp = ssp;
8219         ssp = ssp->next;
8220       }
8221       if (ssp == NULL) {
8222         ssp = SubSourceNew ();
8223         ssp->subtype = 255;
8224         ssp->name = StringSave (sfp->comment);
8225         if (last_ssp == NULL) {
8226           biop->subtype = ssp;
8227         } else {
8228           last_ssp->next = ssp;
8229         }
8230       } else if (StringHasNoText (ssp->name)) {
8231         ssp->name = MemFree (ssp->name);
8232         ssp->name = StringSave (sfp->comment);
8233       } else {
8234         new_note = (CharPtr) MemNew (sizeof(Char) * (StringLen (ssp->name) + StringLen (sfp->comment) + 2));
8235         sprintf (new_note, "%s;%s", ssp->name, sfp->comment);
8236         ssp->name = MemFree (ssp->name);
8237         ssp->name = new_note;
8238       }
8239     }
8240   } else if (sfp->data.choice == SEQFEAT_COMMENT) {
8241     sdp = CreateNewDescriptor (sep, Seq_descr_comment);
8242     sdp->data.ptrvalue = StringSave (sfp->comment);
8243   }
8244 
8245   sfp->idx.deleteme = TRUE;
8246 }
8247 
8248 
CommonConvertFeatToDesc(IteM i,Boolean pub,Boolean src,Boolean com)8249 static void CommonConvertFeatToDesc (IteM i, Boolean pub, Boolean src, Boolean com)
8250 
8251 {
8252   SeqEntryPtr   sep;
8253   SelStructPtr  sel;
8254   SeqFeatPtr    sfp;
8255   FeatToDescData fdd;
8256   BaseFormPtr   bfp;
8257   SeqMgrFeatContext fcontext;
8258 
8259 #ifdef WIN_MAC
8260   bfp = currentFormDataPtr;
8261 #else
8262   bfp = GetObjectExtra (i);
8263 #endif
8264   if (bfp == NULL) return;
8265   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
8266   if (sep == NULL) return;
8267 
8268   fdd.pub = pub;
8269   fdd.src = src;
8270   fdd.com = com;
8271 
8272   sel = ObjMgrGetSelected ();
8273   if (sel != NULL) {
8274     while (sel != NULL) {
8275       if (sel->entityID == bfp->input_entityID && sel->itemtype == OBJ_SEQFEAT) {
8276         sfp = SeqMgrGetDesiredFeature (bfp->input_entityID, NULL, sel->itemID, 0, NULL, &fcontext);
8277         ConvertOneFeatToDesc (sfp, &fdd);
8278       }
8279       sel = sel->next;
8280     }
8281   } else {
8282     VisitFeaturesInSep (sep, &fdd, ConvertOneFeatToDesc);
8283   }
8284   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
8285   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
8286   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
8287 }
8288 
8289 
ConvertPubFeatToDesc(IteM i)8290 static void ConvertPubFeatToDesc (IteM i)
8291 {
8292   CommonConvertFeatToDesc (i, TRUE, FALSE, FALSE);
8293 }
8294 
8295 
ConvertSrcFeatToDesc(IteM i)8296 static void ConvertSrcFeatToDesc (IteM i)
8297 {
8298   CommonConvertFeatToDesc (i, FALSE, TRUE, FALSE);
8299 }
8300 
8301 
ConvertCommentFeatToDesc(IteM i)8302 static void ConvertCommentFeatToDesc (IteM i)
8303 {
8304   CommonConvertFeatToDesc (i, FALSE, FALSE, TRUE);
8305 }
8306 
8307 
8308 
MoveSecondProtName(SeqFeatPtr sfp,Pointer userdata)8309 static void MoveSecondProtName (SeqFeatPtr sfp, Pointer userdata)
8310 
8311 {
8312   ValNodePtr  nxt;
8313   ProtRefPtr  prp;
8314   ValNodePtr  vnp;
8315 
8316   if (sfp == NULL || sfp->data.choice != SEQFEAT_PROT) return;
8317   prp = (ProtRefPtr) sfp->data.value.ptrvalue;
8318   if (prp == NULL) return;
8319   vnp = prp->name;
8320   if (vnp == NULL) return;
8321   nxt = vnp->next;
8322   while (nxt != NULL) {
8323     SetStringValue(&(prp->desc), (CharPtr) nxt->data.ptrvalue, ExistingTextOption_append_semi);
8324     nxt = nxt->next;
8325   }
8326   vnp->next = ValNodeFreeData(vnp->next);
8327 }
8328 
SecondProtNameToDesc(IteM i)8329 static void SecondProtNameToDesc (IteM i)
8330 
8331 {
8332   BaseFormPtr  bfp;
8333   SeqEntryPtr  sep;
8334 
8335 #ifdef WIN_MAC
8336   bfp = currentFormDataPtr;
8337 #else
8338   bfp = GetObjectExtra (i);
8339 #endif
8340   if (bfp == NULL) return;
8341   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
8342   if (sep == NULL) return;
8343   VisitFeaturesInSep (sep, NULL, MoveSecondProtName);
8344   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
8345   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
8346 }
8347 
MoveProtDesc(SeqFeatPtr sfp,Pointer userdata)8348 static void MoveProtDesc (SeqFeatPtr sfp, Pointer userdata)
8349 
8350 {
8351   ProtRefPtr  prp;
8352   CharPtr     str;
8353   ValNodePtr  vnp;
8354 
8355   if (sfp == NULL || sfp->data.choice != SEQFEAT_PROT) return;
8356   prp = (ProtRefPtr) sfp->data.value.ptrvalue;
8357   if (prp == NULL || prp->desc == NULL) return;
8358   vnp = prp->name;
8359   if (vnp == NULL) return;
8360   str = prp->desc;
8361   prp->desc = NULL;
8362   ValNodeAddStr (&(prp->name), 0, str);
8363 }
8364 
ProtDescToSecondName(IteM i)8365 static void ProtDescToSecondName (IteM i)
8366 
8367 {
8368   BaseFormPtr  bfp;
8369   SeqEntryPtr  sep;
8370 
8371 #ifdef WIN_MAC
8372   bfp = currentFormDataPtr;
8373 #else
8374   bfp = GetObjectExtra (i);
8375 #endif
8376   if (bfp == NULL) return;
8377   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
8378   if (sep == NULL) return;
8379   VisitFeaturesInSep (sep, NULL, MoveProtDesc);
8380   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
8381   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
8382 }
8383 
8384 typedef struct ecrepdata {
8385   CharPtr  before;
8386   CharPtr  after;
8387 } EcRepData, PNTR EcRepPtr;
8388 
8389 static ValNodePtr     ec_rep_list = NULL;
8390 static EcRepPtr PNTR  ec_rep_data = NULL;
8391 static Int4           ec_rep_len = 0;
8392 
SortVnpByEcBefore(VoidPtr ptr1,VoidPtr ptr2)8393 static int LIBCALLBACK SortVnpByEcBefore (VoidPtr ptr1, VoidPtr ptr2)
8394 
8395 {
8396   EcRepPtr    erp1, erp2;
8397   CharPtr     str1, str2;
8398   ValNodePtr  vnp1, vnp2;
8399 
8400   if (ptr1 == NULL || ptr2 == NULL) return 0;
8401   vnp1 = *((ValNodePtr PNTR) ptr1);
8402   vnp2 = *((ValNodePtr PNTR) ptr2);
8403   if (vnp1 == NULL || vnp2 == NULL) return 0;
8404   erp1 = (EcRepPtr) vnp1->data.ptrvalue;
8405   erp2 = (EcRepPtr) vnp2->data.ptrvalue;
8406   if (erp1 == NULL || erp2 == NULL) return 0;
8407   str1 = erp1->before;
8408   str2 = erp2->before;
8409   if (str1 == NULL || str2 == NULL) return 0;
8410   return StringCmp (str1, str2);
8411 }
8412 
SetupECReplacementTable(CharPtr file)8413 static void SetupECReplacementTable (CharPtr file)
8414 
8415 {
8416   EcRepPtr    erp;
8417   FileCache   fc;
8418   FILE        *fp = NULL;
8419   Int4        i;
8420   ValNodePtr  last = NULL;
8421   Char        line [512];
8422   Char        path [PATH_MAX];
8423   CharPtr     ptr;
8424   ErrSev      sev;
8425   CharPtr     str;
8426   ValNodePtr  vnp;
8427 
8428   if (ec_rep_data != NULL) return;
8429 
8430   if (FindPath ("ncbi", "ncbi", "data", path, sizeof (path))) {
8431     FileBuildPath (path, NULL, file);
8432     sev = ErrSetMessageLevel (SEV_ERROR);
8433     fp = FileOpen (path, "r");
8434     ErrSetMessageLevel (sev);
8435     if (fp != NULL) {
8436       FileCacheSetup (&fc, fp);
8437 
8438       str = FileCacheReadLine (&fc, line, sizeof (line), NULL);
8439       while (str != NULL) {
8440         if (StringDoesHaveText (str)) {
8441           ptr = StringChr (str, '\t');
8442           if (ptr != NULL) {
8443             *ptr = '\0';
8444             ptr++;
8445             erp = (EcRepPtr) MemNew (sizeof (EcRepData));
8446             if (erp != NULL) {
8447               erp->before = StringSave (str);
8448               erp->after = StringSave (ptr);
8449               vnp = ValNodeAddPointer (&last, 0, (Pointer) erp);
8450               if (ec_rep_list == NULL) {
8451                 ec_rep_list = vnp;
8452               }
8453               last = vnp;
8454             }
8455           }
8456         }
8457         str = FileCacheReadLine (&fc, line, sizeof (line), NULL);
8458       }
8459 
8460       FileClose (fp);
8461       ec_rep_len = ValNodeLen (ec_rep_list);
8462       if (ec_rep_len > 0) {
8463         ec_rep_list = ValNodeSort (ec_rep_list, SortVnpByEcBefore);
8464         ec_rep_data = (EcRepPtr PNTR) MemNew (sizeof (EcRepPtr) * (ec_rep_len + 1));
8465         if (ec_rep_data != NULL) {
8466           for (vnp = ec_rep_list, i = 0; vnp != NULL; vnp = vnp->next, i++) {
8467             erp = (EcRepPtr) vnp->data.ptrvalue;
8468             ec_rep_data [i] = erp;
8469           }
8470         }
8471       }
8472     }
8473   }
8474 }
8475 
GetLocusTagFromProtRef(SeqFeatPtr sfp,CharPtr buf,size_t len)8476 static Boolean GetLocusTagFromProtRef (SeqFeatPtr sfp, CharPtr buf, size_t len)
8477 
8478 {
8479   BioseqPtr          bsp;
8480   SeqFeatPtr         cds;
8481   SeqMgrFeatContext  fcontext;
8482   SeqFeatPtr         gene;
8483   GeneRefPtr         grp;
8484 
8485   if (sfp == NULL || buf == NULL) return FALSE;
8486   grp = SeqMgrGetGeneXref (sfp);
8487   if (grp != NULL) {
8488     if (SeqMgrGeneIsSuppressed (grp)) return FALSE;
8489     if (StringDoesHaveText (grp->locus_tag)) {
8490       StringNCpy_0 (buf, grp->locus_tag, len);
8491       return TRUE;
8492     } else if (StringDoesHaveText (grp->locus)) {
8493       StringNCpy_0 (buf, grp->locus, len);
8494       return TRUE;
8495     }
8496   }
8497   bsp = BioseqFindFromSeqLoc (sfp->location);
8498   if (bsp == NULL) return FALSE;
8499   cds = SeqMgrGetCDSgivenProduct (bsp, &fcontext);
8500   if (cds == NULL) return FALSE;
8501   grp = SeqMgrGetGeneXref (cds);
8502   if (grp != NULL) {
8503     if (SeqMgrGeneIsSuppressed (grp)) return FALSE;
8504     if (StringDoesHaveText (grp->locus_tag)) {
8505       StringNCpy_0 (buf, grp->locus_tag, len);
8506       return TRUE;
8507     } else if (StringDoesHaveText (grp->locus)) {
8508       StringNCpy_0 (buf, grp->locus, len);
8509       return TRUE;
8510     }
8511   }
8512   gene = SeqMgrGetOverlappingGene (cds->location, &fcontext);
8513   if (gene == NULL || gene->data.choice != SEQFEAT_GENE) return FALSE;
8514   grp = (GeneRefPtr) gene->data.value.ptrvalue;
8515   if (grp != NULL) {
8516     if (SeqMgrGeneIsSuppressed (grp)) return FALSE;
8517     if (StringDoesHaveText (grp->locus_tag)) {
8518       StringNCpy_0 (buf, grp->locus_tag, len);
8519       return TRUE;
8520     } else if (StringDoesHaveText (grp->locus)) {
8521       StringNCpy_0 (buf, grp->locus, len);
8522       return TRUE;
8523     }
8524   }
8525   return FALSE;
8526 }
8527 
8528 static Boolean do_ec_zap = FALSE;
8529 static Boolean ec_zap_asked = FALSE;
8530 
ZapBadEC(SeqFeatPtr sfp,Pointer userdata)8531 static void ZapBadEC (SeqFeatPtr sfp, Pointer userdata)
8532 
8533 {
8534   Char        buf [128];
8535   LogInfoPtr  lip;
8536   ProtRefPtr  prp;
8537   CharPtr     str;
8538   ValNodePtr  vnp;
8539 
8540   if (sfp == NULL || sfp->data.choice != SEQFEAT_PROT) return;
8541   prp = (ProtRefPtr) sfp->data.value.ptrvalue;
8542   if (prp == NULL || prp->ec == NULL) return;
8543   lip = (LogInfoPtr) userdata;
8544 
8545   for (vnp = prp->ec; vnp != NULL; vnp = vnp->next) {
8546     str = (CharPtr) vnp->data.ptrvalue;
8547     if (StringHasNoText (str)) continue;
8548     if (ValidateECnumber (str)) continue;
8549     if (! ec_zap_asked) {
8550       if (Message (MSG_YN, "Do you want to delete improperly formatted EC numbers?") == ANS_YES) {
8551         do_ec_zap = TRUE;
8552       }
8553       ec_zap_asked = TRUE;
8554     }
8555     buf [0] = '\0';
8556     GetLocusTagFromProtRef (sfp, buf, sizeof (buf));
8557     if (do_ec_zap) {
8558       if (lip != NULL && lip->fp != NULL) {
8559         fprintf (lip->fp, "%s\tremoved\t%s\n", buf, str);
8560         lip->data_in_log = TRUE;
8561       }
8562       vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
8563     } else {
8564       if (lip != NULL && lip->fp != NULL) {
8565         fprintf (lip->fp, "%s\tbad format\t%s\n", buf, str);
8566         lip->data_in_log = TRUE;
8567       }
8568     }
8569   }
8570 }
8571 
8572 static Boolean do_ec_delete = FALSE;
8573 static Boolean ec_delete_asked = FALSE;
8574 
UpdateProtEC(SeqFeatPtr sfp,Pointer userdata)8575 static void UpdateProtEC (SeqFeatPtr sfp, Pointer userdata)
8576 
8577 {
8578   Char        buf [128];
8579   EcRepPtr    erp;
8580   Int4        L, R, mid;
8581   LogInfoPtr  lip;
8582   ProtRefPtr  prp;
8583   CharPtr     str;
8584   ValNodePtr  vnp;
8585 
8586   if (sfp == NULL || sfp->data.choice != SEQFEAT_PROT) return;
8587   prp = (ProtRefPtr) sfp->data.value.ptrvalue;
8588   if (prp == NULL || prp->ec == NULL) return;
8589   lip = (LogInfoPtr) userdata;
8590 
8591   for (vnp = prp->ec; vnp != NULL; vnp = vnp->next) {
8592     str = (CharPtr) vnp->data.ptrvalue;
8593     if (StringHasNoText (str)) continue;
8594     if (! ValidateECnumber (str)) continue;
8595     L = 0;
8596     R = ec_rep_len - 1;
8597     while (L < R) {
8598       mid = (L + R) / 2;
8599       erp = ec_rep_data [(int) mid];
8600       if (erp != NULL && StringCmp (erp->before, str) < 0) {
8601         L = mid + 1;
8602       } else {
8603         R = mid;
8604       }
8605     }
8606     erp = ec_rep_data [(int) R];
8607     if (erp != NULL && StringCmp (erp->before, str) == 0) {
8608       buf [0] = '\0';
8609       GetLocusTagFromProtRef (sfp, buf, sizeof (buf));
8610       if (StringChr (erp->after, '\t') == NULL) {
8611         if (lip != NULL && lip->fp != NULL) {
8612           fprintf (lip->fp, "%s\treplaced\t%s\t%s\n", buf, erp->before, erp->after);
8613           lip->data_in_log = TRUE;
8614         }
8615         vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
8616         vnp->data.ptrvalue = StringSave (erp->after);
8617       } else {
8618         if (! ec_delete_asked) {
8619           if (Message (MSG_YN, "Do you want to delete EC numbers replaced by more than one number?") == ANS_YES) {
8620             do_ec_delete = TRUE;
8621           }
8622           ec_delete_asked = TRUE;
8623         }
8624         if (do_ec_delete) {
8625           if (lip != NULL && lip->fp != NULL) {
8626             fprintf (lip->fp, "%s\tsplit\t%s\n", buf, erp->before);
8627             lip->data_in_log = TRUE;
8628           }
8629           vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
8630         } else {
8631           if (lip != NULL && lip->fp != NULL) {
8632             fprintf (lip->fp, "%s\tambiguous\t%s\t%s\n", buf, erp->before, erp->after);
8633             lip->data_in_log = TRUE;
8634           }
8635         }
8636       }
8637     }
8638   }
8639 }
8640 
8641 static Boolean do_bad_delete = FALSE;
8642 static Boolean do_bad_asked = FALSE;
8643 
DeleteBadProtEC(SeqFeatPtr sfp,Pointer userdata)8644 static void DeleteBadProtEC (SeqFeatPtr sfp, Pointer userdata)
8645 
8646 {
8647   Char        buf [128];
8648   LogInfoPtr  lip;
8649   ProtRefPtr  prp;
8650   CharPtr     str;
8651   ValNodePtr  vnp;
8652 
8653   if (sfp == NULL || sfp->data.choice != SEQFEAT_PROT) return;
8654   prp = (ProtRefPtr) sfp->data.value.ptrvalue;
8655   if (prp == NULL || prp->ec == NULL) return;
8656   lip = (LogInfoPtr) userdata;
8657 
8658   for (vnp = prp->ec; vnp != NULL; vnp = vnp->next) {
8659     str = (CharPtr) vnp->data.ptrvalue;
8660     if (StringHasNoText (str)) continue;
8661     if (ValidateECnumber (str) && (! ECnumberNotInList (str))) continue;
8662     if (! do_bad_asked) {
8663       if (Message (MSG_YN, "Do you want to delete unrecognized EC numbers?") == ANS_YES) {
8664         do_bad_delete = TRUE;
8665       }
8666       do_bad_asked = TRUE;
8667     }
8668     buf [0] = '\0';
8669     GetLocusTagFromProtRef (sfp, buf, sizeof (buf));
8670     if (do_bad_delete) {
8671       if (lip != NULL && lip->fp != NULL) {
8672         fprintf (lip->fp, "%s\tdeleted\t%s\n", buf, str);
8673         lip->data_in_log = TRUE;
8674       }
8675       vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
8676     }
8677   }
8678 }
8679 
UpdateECNumbersBaseForm(BaseFormPtr bfp)8680 static void UpdateECNumbersBaseForm (BaseFormPtr bfp)
8681 
8682 {
8683   LogInfoPtr   lip;
8684   SeqEntryPtr  sep;
8685 
8686   if (bfp == NULL) return;
8687   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
8688   if (sep == NULL) return;
8689   SetupECReplacementTable ("ecnum_replaced.txt");
8690 
8691   lip = OpenLog ("EC_numbers Replaced");
8692   do_ec_zap = FALSE;
8693   ec_zap_asked = FALSE;
8694   do_ec_delete = FALSE;
8695   ec_delete_asked = FALSE;
8696   do_bad_delete = FALSE;
8697   do_bad_asked = FALSE;
8698 
8699   VisitFeaturesInSep (sep, (Pointer) lip, ZapBadEC);
8700   if (ec_rep_data != NULL && ec_rep_len > 0) {
8701     VisitFeaturesInSep (sep, (Pointer) lip, UpdateProtEC);
8702   }
8703   VisitFeaturesInSep (sep, (Pointer) lip, DeleteBadProtEC);
8704 
8705   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
8706   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
8707 
8708   CloseLog (lip);
8709   lip = FreeLog (lip);
8710 }
8711 
UpdateECnumbers(IteM i)8712 static void UpdateECnumbers (IteM i)
8713 
8714 {
8715   BaseFormPtr  bfp;
8716 
8717 #ifdef WIN_MAC
8718   bfp = currentFormDataPtr;
8719 #else
8720   bfp = GetObjectExtra (i);
8721 #endif
8722 
8723   UpdateECNumbersBaseForm (bfp);
8724 }
8725 
8726 
8727 typedef struct icrepdata {
8728   CharPtr  code;
8729   CharPtr  name;
8730 } IcRepData, PNTR IcRepPtr;
8731 
8732 static ValNodePtr     ic_rep_list = NULL;
8733 static IcRepPtr PNTR  ic_rep_data = NULL;
8734 static Int4           ic_rep_len = 0;
8735 
SortVnpByInstituteName(VoidPtr ptr1,VoidPtr ptr2)8736 static int LIBCALLBACK SortVnpByInstituteName (VoidPtr ptr1, VoidPtr ptr2)
8737 
8738 {
8739   int         compare;
8740   IcRepPtr    irp1, irp2;
8741   CharPtr     str1, str2;
8742   ValNodePtr  vnp1, vnp2;
8743 
8744   if (ptr1 == NULL || ptr2 == NULL) return 0;
8745   vnp1 = *((ValNodePtr PNTR) ptr1);
8746   vnp2 = *((ValNodePtr PNTR) ptr2);
8747   if (vnp1 == NULL || vnp2 == NULL) return 0;
8748   irp1 = (IcRepPtr) vnp1->data.ptrvalue;
8749   irp2 = (IcRepPtr) vnp2->data.ptrvalue;
8750   if (irp1 == NULL || irp2 == NULL) return 0;
8751   str1 = irp1->name;
8752   str2 = irp2->name;
8753   if (str1 == NULL || str2 == NULL) return 0;
8754   compare = StringCmp (str1, str2);
8755   if (compare > 0) {
8756     return 1;
8757   } else if (compare < 0) {
8758     return -1;
8759   }
8760   str1 = irp1->code;
8761   str2 = irp2->code;
8762   if (str1 == NULL || str2 == NULL) return 0;
8763   compare = StringCmp (str1, str2);
8764   if (compare > 0) {
8765     return 1;
8766   } else if (compare < 0) {
8767     return -1;
8768   }
8769   return 0;
8770 }
8771 
SetupInstituteCodeNameTable(void)8772 static void SetupInstituteCodeNameTable (void)
8773 
8774 {
8775   FileCache   fc;
8776   CharPtr     file = "institution_codes.txt";
8777   FILE        *fp = NULL;
8778   Int4        i;
8779   IcRepPtr    irp;
8780   ValNodePtr  last = NULL;
8781   Char        line [512];
8782   Char        path [PATH_MAX];
8783   CharPtr     ptr;
8784   ErrSev      sev;
8785   CharPtr     str;
8786   ValNodePtr  vnp;
8787 
8788   if (ic_rep_data != NULL) return;
8789 
8790   if (FindPath ("ncbi", "ncbi", "data", path, sizeof (path))) {
8791     FileBuildPath (path, NULL, file);
8792     sev = ErrSetMessageLevel (SEV_ERROR);
8793     fp = FileOpen (path, "r");
8794     ErrSetMessageLevel (sev);
8795     if (fp != NULL) {
8796       FileCacheSetup (&fc, fp);
8797 
8798       str = FileCacheReadLine (&fc, line, sizeof (line), NULL);
8799       while (str != NULL) {
8800         if (StringDoesHaveText (str)) {
8801           ptr = StringChr (str, '\t');
8802           if (ptr != NULL) {
8803             *ptr = '\0';
8804             ptr++;
8805             ptr = StringChr (ptr, '\t');
8806             if (ptr != NULL) {
8807               *ptr = '\0';
8808               ptr++;
8809               irp = (IcRepPtr) MemNew (sizeof (IcRepData));
8810               if (irp != NULL) {
8811                 TrimSpacesAroundString (str);
8812                 TrimSpacesAroundString (ptr);
8813                 irp->code = StringSave (str);
8814                 irp->name = StringSave (ptr);
8815                 vnp = ValNodeAddPointer (&last, 0, (Pointer) irp);
8816                 if (ic_rep_list == NULL) {
8817                   ic_rep_list = vnp;
8818                 }
8819                 last = vnp;
8820               }
8821             }
8822           }
8823         }
8824         str = FileCacheReadLine (&fc, line, sizeof (line), NULL);
8825       }
8826 
8827       FileClose (fp);
8828       ic_rep_len = ValNodeLen (ic_rep_list);
8829       if (ic_rep_len > 0) {
8830         ic_rep_list = ValNodeSort (ic_rep_list, SortVnpByInstituteName);
8831         ic_rep_data = (IcRepPtr PNTR) MemNew (sizeof (IcRepPtr) * (ic_rep_len + 1));
8832         if (ic_rep_data != NULL) {
8833           for (vnp = ic_rep_list, i = 0; vnp != NULL; vnp = vnp->next, i++) {
8834             irp = (IcRepPtr) vnp->data.ptrvalue;
8835             ic_rep_data [i] = irp;
8836           }
8837         }
8838       }
8839     }
8840   }
8841 }
8842 
CheckForInstitutionFullName(CharPtr name,BoolPtr ambigP)8843 static CharPtr CheckForInstitutionFullName (CharPtr name, BoolPtr ambigP)
8844 
8845 {
8846   CharPtr   code = NULL;
8847   IcRepPtr  irp;
8848   Int4      L, R, mid;
8849 
8850   if (ambigP != NULL) {
8851     *ambigP = FALSE;
8852   }
8853   if (StringHasNoText (name)) return NULL;
8854   L = 0;
8855   R = ic_rep_len - 1;
8856   while (L < R) {
8857     mid = (L + R) / 2;
8858     irp = ic_rep_data [(int) mid];
8859     if (irp != NULL && StringCmp (irp->name, name) < 0) {
8860       L = mid + 1;
8861     } else {
8862       R = mid;
8863     }
8864   }
8865   irp = ic_rep_data [(int) R];
8866   if (irp != NULL && StringCmp (irp->name, name) == 0) {
8867     code = irp->code;
8868     /* need to check for uniqueness */
8869     if (R < ic_rep_len - 1) {
8870       irp = ic_rep_data [(int) R + 1];
8871       if (irp != NULL && StringCmp (irp->name, name) == 0) {
8872         if (ambigP != NULL) {
8873           *ambigP = TRUE;
8874         }
8875         return NULL;
8876       }
8877     }
8878   }
8879   return code;
8880 }
8881 
ConvertInstitutionName(OrgModPtr mod)8882 static void ConvertInstitutionName (OrgModPtr mod)
8883 
8884 {
8885   Boolean  ambig = FALSE;
8886   Char     buf [512];
8887   CharPtr  code = NULL, inst = NULL, id = NULL, coll = NULL, new_val;
8888 
8889   if (mod == NULL) return;
8890 
8891   StringNCpy_0 (buf, mod->subname, sizeof (buf));
8892   if (StringChr (buf, ':') == NULL) return;
8893   if (! ParseStructuredVoucher (buf, &inst, &id)) return;
8894   if (inst == NULL) return;
8895 
8896   if (VoucherInstitutionIsValid (inst)) return;
8897 
8898   /* ignore personal collections */
8899   if (StringNICmp (inst, "personal", 8) == 0) return;
8900 
8901   coll = StringChr (inst, ':');
8902   if (coll != NULL) {
8903     *coll = '\0';
8904     if (VoucherInstitutionIsValid (inst)) {
8905       /* DNA is a valid collection for any institution (using bio_material) */
8906       if (StringCmp (coll, "DNA") != 0) return;
8907     }
8908     *coll = ':';
8909   }
8910 
8911   code = CheckForInstitutionFullName (inst, &ambig);
8912   if (StringHasNoText (code)) return;
8913   if (ambig) {
8914     Message (MSG_POST, "Institution '%s' maps to multiple codes", inst);
8915     return;
8916   }
8917 
8918   mod->subname = MemFree (mod->subname);
8919   if (StringHasNoText (id)) {
8920     mod->subname = StringSave (code);
8921   } else {
8922     new_val = (CharPtr) MemNew (sizeof (Char) * (StringLen (code) + StringLen (id) + 2));
8923     sprintf (new_val, "%s:%s", code, id);
8924     mod->subname = new_val;
8925   }
8926 }
8927 
InstitutionNameToCode(BioSourcePtr biop,Pointer userdata)8928 static void InstitutionNameToCode (BioSourcePtr biop, Pointer userdata)
8929 
8930 {
8931   OrgNamePtr  onp;
8932   OrgModPtr   omp;
8933   OrgRefPtr   orp;
8934 
8935   if (biop == NULL) return;
8936   orp = biop->org;
8937   if (orp == NULL) return;
8938   onp = orp->orgname;
8939   if (onp == NULL) return;
8940   for (omp = onp->mod; omp != NULL; omp = omp->next) {
8941     if (omp->subtype == ORGMOD_specimen_voucher ||
8942         omp->subtype == ORGMOD_culture_collection ||
8943         omp->subtype == ORGMOD_bio_material) {
8944       ConvertInstitutionName (omp);
8945     }
8946   }
8947 }
8948 
UpdateVoucherName(IteM i)8949 static void UpdateVoucherName (IteM i)
8950 
8951 {
8952   BaseFormPtr  bfp;
8953   SeqEntryPtr  sep;
8954 
8955 #ifdef WIN_MAC
8956   bfp = currentFormDataPtr;
8957 #else
8958   bfp = GetObjectExtra (i);
8959 #endif
8960   if (bfp == NULL) return;
8961   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
8962   if (sep == NULL) return;
8963   SetupInstituteCodeNameTable ();
8964   if (ic_rep_data != NULL && ic_rep_len > 0) {
8965     VisitBioSourcesInSep (sep, NULL, InstitutionNameToCode);
8966   }
8967   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
8968   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
8969 }
8970 
DoRemoveBadCollection(BioSourcePtr biop,Pointer userdata)8971 static void DoRemoveBadCollection (BioSourcePtr biop, Pointer userdata)
8972 
8973 {
8974   OrgNamePtr  onp;
8975   OrgModPtr   omp;
8976   OrgRefPtr   orp;
8977   CharPtr     str;
8978 
8979   if (biop == NULL) return;
8980   orp = biop->org;
8981   if (orp == NULL) return;
8982   onp = orp->orgname;
8983   if (onp == NULL) return;
8984   for (omp = onp->mod; omp != NULL; omp = omp->next) {
8985     if (omp->subtype == ORGMOD_specimen_voucher ||
8986         omp->subtype == ORGMOD_culture_collection ||
8987         omp->subtype == ORGMOD_bio_material) {
8988       str = RemoveBadInstitutionCollection (omp);
8989       if (str != NULL) {
8990         omp->subname = MemFree (omp->subname);
8991         omp->subname = str;
8992       }
8993     }
8994   }
8995 }
8996 
RemoveBadCollectionCode(IteM i)8997 static void RemoveBadCollectionCode (IteM i)
8998 
8999 {
9000   BaseFormPtr  bfp;
9001   SeqEntryPtr  sep;
9002 
9003 #ifdef WIN_MAC
9004   bfp = currentFormDataPtr;
9005 #else
9006   bfp = GetObjectExtra (i);
9007 #endif
9008   if (bfp == NULL) return;
9009   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
9010   if (sep == NULL) return;
9011   SetupInstituteCodeNameTable ();
9012   if (ic_rep_data != NULL && ic_rep_len > 0) {
9013     VisitBioSourcesInSep (sep, NULL, DoRemoveBadCollection);
9014   }
9015   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9016   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9017 }
9018 
9019 
DoRemoveBadCountry(BioSourcePtr biop,Pointer userdata)9020 static void DoRemoveBadCountry (BioSourcePtr biop, Pointer userdata)
9021 
9022 {
9023   OrgNamePtr  onp;
9024   OrgModPtr   omp;
9025   OrgRefPtr   orp;
9026   CharPtr     str;
9027 
9028   if (biop == NULL) return;
9029   orp = biop->org;
9030   if (orp == NULL) return;
9031   onp = orp->orgname;
9032   if (onp == NULL) return;
9033   for (omp = onp->mod; omp != NULL; omp = omp->next) {
9034     if (omp->subtype == ORGMOD_specimen_voucher ||
9035         omp->subtype == ORGMOD_culture_collection ||
9036         omp->subtype == ORGMOD_bio_material) {
9037       str = RemoveBadInstitutionCountry (omp);
9038       if (str != NULL) {
9039         omp->subname = MemFree (omp->subname);
9040         omp->subname = str;
9041       }
9042     }
9043   }
9044 }
9045 
RemoveBadCountry(IteM i)9046 static void RemoveBadCountry (IteM i)
9047 
9048 {
9049   BaseFormPtr  bfp;
9050   SeqEntryPtr  sep;
9051 
9052 #ifdef WIN_MAC
9053   bfp = currentFormDataPtr;
9054 #else
9055   bfp = GetObjectExtra (i);
9056 #endif
9057   if (bfp == NULL) return;
9058   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
9059   if (sep == NULL) return;
9060   SetupInstituteCodeNameTable ();
9061   if (ic_rep_data != NULL && ic_rep_len > 0) {
9062     VisitBioSourcesInSep (sep, NULL, DoRemoveBadCountry);
9063   }
9064   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9065   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9066 }
9067 
9068 
ParseGoTermsFromUserFieldsItem(IteM i)9069 static void ParseGoTermsFromUserFieldsItem (IteM i)
9070 
9071 {
9072   BaseFormPtr  bfp;
9073   SeqEntryPtr  sep;
9074 
9075 #ifdef WIN_MAC
9076   bfp = currentFormDataPtr;
9077 #else
9078   bfp = GetObjectExtra (i);
9079 #endif
9080   if (bfp == NULL) return;
9081   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
9082   if (sep == NULL) return;
9083   ParseGoTermsFromFields (sep);
9084   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
9085   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
9086 }
9087 
9088 
9089 /*---------------------------------------------------------------------*/
9090 /*                                                                     */
9091 /* HasInternalStops () -- Checks to see if a given protein has         */
9092 /*                        any internal stop codons.                    */
9093 /*                                                                     */
9094 /*   Returns : TRUE -- If internal stop codons are found.              */
9095 /*             FALSE -- If internal stop codons are NOT found.         */
9096 /*                                                                     */
9097 /*---------------------------------------------------------------------*/
9098 
HasInternalStops(SeqFeatPtr sfp)9099 static Boolean HasInternalStops (SeqFeatPtr sfp)
9100 {
9101   ByteStorePtr  bs;
9102   CharPtr       protStr;
9103   CharPtr       stopStr;
9104   Boolean       partial5, partial3;
9105   Boolean       rval = FALSE;
9106 
9107   if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) {
9108     return FALSE;
9109   }
9110   /* Get the protein sequence in ASCII chars */
9111 
9112   bs = ProteinFromCdRegionEx (sfp, TRUE, FALSE);
9113   if (NULL == bs)
9114     return TRUE;
9115   protStr = BSMerge (bs, NULL);
9116   bs = BSFree (bs);
9117 
9118   /* If the is a "*" in the str in any position  */
9119   /* except at the end, then we have an internal */
9120   /* stop codon.                                 */
9121 
9122   CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
9123   stopStr = StringStr (protStr, "*");
9124   if (stopStr != NULL && (partial3 || StringLen (stopStr) > 1)) {
9125     rval = TRUE;
9126   }
9127   MemFree (protStr);
9128   return rval;
9129 }
9130 
9131 
HasBadStartCodon(SeqFeatPtr sfp)9132 static Boolean HasBadStartCodon (SeqFeatPtr sfp)
9133 {
9134   Boolean partial5, partial3;
9135   ByteStorePtr  bs;
9136   CharPtr       protStr;
9137   Boolean       rval = FALSE;
9138 
9139   if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) {
9140     return FALSE;
9141   }
9142 
9143   CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
9144   if (partial5) {
9145     return FALSE;
9146   }
9147 
9148   bs = ProteinFromCdRegionEx (sfp, TRUE, FALSE);
9149   if (bs == NULL) {
9150     rval = FALSE;
9151   } else {
9152     protStr = BSMerge (bs, NULL);
9153     bs = BSFree (bs);
9154     if (StringNCmp (protStr, "M", 1) != 0) {
9155       rval = TRUE;
9156     }
9157     protStr = MemFree (protStr);
9158   }
9159   return rval;
9160 }
9161 
9162 
HasBadStopCodon(SeqFeatPtr sfp)9163 static Boolean HasBadStopCodon (SeqFeatPtr sfp)
9164 {
9165   Boolean partial5, partial3;
9166   ByteStorePtr  bs;
9167   CharPtr       protStr;
9168   Boolean       rval = FALSE;
9169 
9170   if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) {
9171     return FALSE;
9172   }
9173 
9174   CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
9175   if (partial3) {
9176     return FALSE;
9177   }
9178 
9179   bs = ProteinFromCdRegionEx (sfp, TRUE, FALSE);
9180   if (bs == NULL) {
9181     rval = FALSE;
9182   } else {
9183     protStr = BSMerge (bs, NULL);
9184     bs = BSFree (bs);
9185     if (protStr[StringLen (protStr) - 1] != '*') {
9186       rval = TRUE;
9187     }
9188     protStr = MemFree (protStr);
9189   }
9190   return rval;
9191 }
9192 
9193 
9194 extern Boolean
ConvertOneCDSToMiscFeat(SeqFeatPtr sfp,Boolean viral,Boolean must_have_stops,CDSConversionOptsPtr opts)9195 ConvertOneCDSToMiscFeat
9196 (SeqFeatPtr sfp,
9197  Boolean viral,
9198  Boolean must_have_stops,
9199  CDSConversionOptsPtr opts)
9200 {
9201   CdRegionPtr          cdrp;
9202   ImpFeatPtr           ifp;
9203   CharPtr              noteStr;
9204   BioseqPtr            protBsp;
9205   SeqMgrFeatContext    protContext, mRNAcontext;
9206   CharPtr              protName = NULL;
9207   SeqFeatPtr           protSfp, mRNA, gene;
9208   ProtRefPtr           prp;
9209   ValNodePtr           vnp;
9210   Int4                 note_len = 0;
9211   CharPtr              viral_fmt = "nonfunctional %s due to mutation";
9212   CharPtr              similar_fmt = "similar to %s";
9213 
9214   if (sfp == NULL
9215       || sfp->data.choice != SEQFEAT_CDREGION
9216       || sfp->product == NULL
9217       || must_have_stops && !HasInternalStops (sfp))
9218   {
9219     return FALSE;
9220   }
9221 
9222   /* Get the CD region part of the feature, and */
9223   /* the associated protein bioseq.             */
9224 
9225   cdrp = (CdRegionPtr) sfp->data.value.ptrvalue;
9226   protBsp = BioseqFindFromSeqLoc (sfp->product);
9227 
9228   if (protBsp == NULL) return FALSE;
9229 
9230   /* remove the overlapping mRNA feature if requested */
9231   if (opts != NULL && opts->remove_mrna) {
9232     mRNA = SeqMgrGetOverlappingmRNA (sfp->location, &mRNAcontext);
9233     if (mRNA != NULL) {
9234       mRNA->idx.deleteme = TRUE;
9235     }
9236   }
9237 
9238   /* remove the overlapping gene feature if requested */
9239   if (opts != NULL && opts->remove_gene) {
9240     gene = SeqMgrGetOverlappingGene (sfp->location, &mRNAcontext);
9241     if (gene != NULL) {
9242       gene->idx.deleteme = TRUE;
9243     }
9244   }
9245 
9246 
9247   /* Convert the CDS feature to a misc_feat */
9248 
9249   CdRegionFree (cdrp);
9250   sfp->data.value.ptrvalue = NULL;
9251 
9252   ifp = ImpFeatNew ();
9253   if (NULL == ifp) return FALSE;
9254   ifp->key = StringSave ("misc_feature");
9255 
9256   sfp->data.choice = SEQFEAT_IMP;
9257   sfp->data.value.ptrvalue = (Pointer) ifp;
9258 
9259   if (! IsFeatInGPS (sfp) || (opts != NULL && opts->remove_transcript_id))
9260   {
9261     sfp->product = SeqLocFree (sfp->product);
9262   }
9263 
9264   /* Add a name key to the misc_feature */
9265 
9266   protSfp = SeqMgrGetBestProteinFeature (protBsp, &protContext);
9267   if (protSfp != NULL)
9268   {
9269     prp = (ProtRefPtr) protSfp->data.value.ptrvalue;
9270 
9271     if (prp != NULL)
9272     {
9273       note_len = StringLen (sfp->comment) + StringLen (prp->desc) + 5;
9274 
9275       vnp = prp->name;
9276       if (NULL != vnp)
9277       {
9278         protName = (CharPtr) vnp->data.ptrvalue;
9279         if (NULL != protName)
9280         {
9281           if (viral) {
9282             note_len += StringLen (viral_fmt) + StringLen (protName);
9283           } else {
9284             note_len += StringLen (similar_fmt) + StringLen (protName);
9285           }
9286         }
9287       }
9288       noteStr = (CharPtr) MemNew (sizeof (Char) * note_len);
9289 
9290       if (NULL != protName) {
9291         if (viral) {
9292           sprintf (noteStr, viral_fmt, protName);
9293         } else {
9294           sprintf (noteStr, similar_fmt, protName);
9295         }
9296       }
9297       if (!StringHasNoText (prp->desc)) {
9298         if (!StringHasNoText (noteStr)) {
9299           StringCat (noteStr, "; ");
9300         }
9301         StringCat (noteStr, prp->desc);
9302       }
9303       if (!StringHasNoText (sfp->comment)) {
9304         if (!StringHasNoText (noteStr)) {
9305           StringCat (noteStr, "; ");
9306         }
9307         StringCat (noteStr, sfp->comment);
9308       }
9309       sfp->comment = MemFree (sfp->comment);
9310       sfp->comment = noteStr;
9311     }
9312   }
9313 
9314   /* Delete the protein Bioseq that */
9315   /* the CDS points to.             */
9316 
9317   protBsp->idx.deleteme = TRUE;
9318 
9319   /* set the subtype to zero so that it will be reindexed */
9320   sfp->idx.subtype = 0;
9321   return TRUE;
9322 }
9323 
9324 
ConvertCDSToMiscFeat(SeqFeatPtr sfp,Pointer userdata)9325 extern void ConvertCDSToMiscFeat (SeqFeatPtr sfp, Pointer userdata)
9326 {
9327   CDStoMiscFeatPtr     cmfp = NULL;
9328   Boolean              viral = FALSE;
9329   Boolean              must_have_stops = TRUE;
9330   CDSConversionOptsPtr opts = NULL;
9331 
9332   if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION
9333       || sfp->product == NULL)
9334   {
9335     return;
9336   }
9337 
9338   if (userdata != NULL) {
9339     cmfp = (CDStoMiscFeatPtr) userdata;
9340     viral = cmfp->viral;
9341     must_have_stops = cmfp->must_have_stops;
9342     opts = cmfp->opts;
9343   }
9344 
9345   ConvertOneCDSToMiscFeat (sfp, viral, must_have_stops, opts);
9346 }
9347 
ChangeOnlyPseudoOption(ButtoN b)9348 static void ChangeOnlyPseudoOption (ButtoN b)
9349 {
9350   GrouP nonpseudo_opts;
9351 
9352   nonpseudo_opts = (GrouP) GetObjectExtra (b);
9353   if (nonpseudo_opts != NULL) {
9354     if (GetStatus (b)) {
9355       Disable (nonpseudo_opts);
9356     } else {
9357       Enable (nonpseudo_opts);
9358     }
9359   }
9360 }
9361 
9362 
9363 extern CDSConversionOptsPtr
GetCDSConversionOptions(Boolean all_are_pseudo,Boolean any_pseudo,Boolean any_gps,BoolPtr cancel)9364 GetCDSConversionOptions (Boolean all_are_pseudo, Boolean any_pseudo, Boolean any_gps, BoolPtr cancel)
9365 {
9366   ModalAcceptCancelData acd;
9367   WindoW                w;
9368   GrouP                 h, g, c, nonpseudo_opts;
9369   ButtoN                b, remove_mrna_btn, remove_gene_btn, remove_transcript_btn = NULL, only_pseudo_btn = NULL;
9370   CDSConversionOptsPtr opts;
9371 
9372   if (cancel == NULL) return NULL;
9373 
9374   *cancel = FALSE;
9375   opts = (CDSConversionOptsPtr) MemNew (sizeof(CDSConversionOptsData));
9376 
9377   opts->all_are_pseudo = all_are_pseudo;
9378 
9379   if (opts->all_are_pseudo)
9380   {
9381     opts->remove_mrna = FALSE;
9382     opts->remove_gene = FALSE;
9383     opts->only_pseudo = FALSE;
9384     opts->remove_transcript_id = FALSE;
9385     return opts;
9386   }
9387 
9388   acd.accepted = FALSE;
9389   acd.cancelled = FALSE;
9390 
9391   w = ModalWindow(-20, -13, -10, -10, NULL);
9392   h = HiddenGroup (w, -1, 0, NULL);
9393   SetGroupSpacing (h, 10, 10);
9394 
9395   g = NormalGroup (h, 0, 10, "CDS Conversion Options", programFont, NULL);
9396   SetGroupSpacing (g, 10, 10);
9397 
9398   if (any_pseudo)
9399   {
9400     only_pseudo_btn = CheckBox (g, "Only Convert Pseudo CDS", ChangeOnlyPseudoOption);
9401     SetStatus (only_pseudo_btn, FALSE);
9402   }
9403 
9404   nonpseudo_opts = HiddenGroup (g, 0, 3, NULL);
9405   remove_mrna_btn = CheckBox (nonpseudo_opts, "Remove Overlapping mRNAs", NULL);
9406   SetStatus (remove_mrna_btn, FALSE);
9407   remove_gene_btn = CheckBox (nonpseudo_opts, "Remove Overlapping Genes", NULL);
9408   SetStatus (remove_gene_btn, FALSE);
9409   if (any_gps)
9410   {
9411     remove_transcript_btn = CheckBox (nonpseudo_opts, "Remove Transcript ID", NULL);
9412     SetStatus (remove_transcript_btn, FALSE);
9413   }
9414 
9415   if (only_pseudo_btn != NULL)
9416   {
9417     SetObjectExtra (only_pseudo_btn, nonpseudo_opts, NULL);
9418   }
9419 
9420   c = HiddenGroup (h, 3, 0, NULL);
9421   b = DefaultButton (c, "Accept", ModalAcceptButton);
9422   SetObjectExtra (b, &acd, NULL);
9423   b = PushButton (c, "Cancel", ModalCancelButton);
9424   SetObjectExtra (b, &acd, NULL);
9425   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) nonpseudo_opts, (HANDLE) c, (HANDLE) only_pseudo_btn, NULL);
9426 
9427   Show(w);
9428   Select (w);
9429   while (!acd.accepted && ! acd.cancelled)
9430   {
9431     ProcessExternalEvent ();
9432     Update ();
9433   }
9434   ProcessAnEvent ();
9435   if (acd.accepted)
9436   {
9437     if (only_pseudo_btn == NULL || !GetStatus (only_pseudo_btn))
9438     {
9439       opts->only_pseudo = FALSE;
9440       opts->remove_mrna = GetStatus (remove_mrna_btn);
9441       opts->remove_gene = GetStatus (remove_gene_btn);
9442       opts->remove_transcript_id = GetStatus (remove_transcript_btn);
9443     }
9444     else
9445     {
9446       opts->only_pseudo = TRUE;
9447       opts->remove_mrna = FALSE;
9448       opts->remove_gene = FALSE;
9449       opts->remove_transcript_id = FALSE;
9450     }
9451   }
9452   else
9453   {
9454     *cancel = TRUE;
9455     opts = MemFree (opts);
9456   }
9457 
9458   Remove (w);
9459   return opts;
9460 }
9461 
9462 #define kWaitingOnCodingRegion "GenBank staff are still waiting for submitters to provide appropriate coding region information."
9463 
AddNonredundantCommentDescriptor(BioseqPtr bsp,CharPtr text)9464 static void AddNonredundantCommentDescriptor (BioseqPtr bsp, CharPtr text)
9465 {
9466   SeqDescrPtr sdp;
9467   SeqMgrDescContext context;
9468   Boolean found = FALSE;
9469 
9470   if (bsp == NULL || StringHasNoText (text)) {
9471     return;
9472   }
9473 
9474   for (sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_comment, &context);
9475        sdp != NULL && !found;
9476        sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_comment, &context)) {
9477     if (StringICmp (sdp->data.ptrvalue, text) == 0) {
9478       found = TRUE;
9479     }
9480   }
9481   if (!found) {
9482     sdp = CreateNewDescriptorOnBioseq (bsp, Seq_descr_comment);
9483     sdp->data.ptrvalue = StringSave (text);
9484   }
9485 }
9486 
9487 
9488 typedef struct addindexercomment {
9489   CharPtr comment_text;
9490   Boolean add_unverified_feat;
9491   Boolean add_unverified_org;
9492   ValNodePtr constraint;
9493 } AddIndexerCommentData, PNTR AddIndexerCommentPtr;
9494 
9495 
AddIndexerCommentCallback(BioseqPtr bsp,Pointer data)9496 static void AddIndexerCommentCallback (BioseqPtr bsp, Pointer data)
9497 {
9498   AddIndexerCommentPtr a;
9499   UserObjectPtr uop;
9500 
9501   if (bsp == NULL || (a = (AddIndexerCommentPtr) data) == NULL
9502       || (!a->add_unverified_feat && !a->add_unverified_org && StringHasNoText (a->comment_text))
9503       || !DoesObjectMatchConstraintChoiceSet(OBJ_BIOSEQ, bsp, a->constraint)) {
9504     return;
9505   }
9506   if (a->add_unverified_feat || a->add_unverified_org) {
9507     uop = AddUnverifiedUserObjectToBioseq(bsp);
9508     if (uop != NULL) {
9509       if (a->add_unverified_feat) {
9510         AddStringToUnverifiedUserObject (uop, "Type", "Features");
9511       }
9512       if (a->add_unverified_org) {
9513         AddStringToUnverifiedUserObject (uop, "Type", "Organism");
9514       }
9515     }
9516   } else {
9517     AddNonredundantCommentDescriptor (bsp, a->comment_text);
9518   }
9519 }
9520 
9521 
9522 typedef struct addindexercommentform {
9523   FORM_MESSAGE_BLOCK
9524 
9525   PopuP comment_text_choice;
9526   TexT  comment_text;
9527   DialoG constraint;
9528   ButtoN leave_dlg_up;
9529 } AddIndexerCommentFormData, PNTR AddIndexerCommentFormPtr;
9530 
9531 
9532 static const CharPtr kStaticIndexerComments[] = {
9533   "Unverified Features",
9534   "Unverified Organism",
9535   "Unverified Features and Organism",
9536   "Sequences were screened for chimeras by the submitter using",
9537   "Annotation was added by the NCBI Prokaryotic Genomes Automatic Annotation Pipeline Group. Information about the Pipeline can be found here: http://www.ncbi.nlm.nih.gov/genomes/static/Pipeline.html. Please be aware that the annotation is done automatically with little or no manual curation.",
9538   "Genome was manually curated based on annotation generated by the NCBI Prokaryotic Genomes Automatic Annotation Pipeline Group. Information about the Pipeline can be found here: http://www.ncbi.nlm.nih.gov/genomes/static/Pipeline.html.",
9539   kWaitingOnCodingRegion,
9540   "GenBank staff are still waiting for submitters to provide appropriate feature information."
9541 };
9542 
9543 static const CharPtr kStaticIndexerCommentNames[] = {
9544   NULL,
9545   NULL,
9546   NULL,
9547   NULL,
9548   "PGAAP unmodified",
9549   "PGAAP modified",
9550   NULL,
9551   NULL
9552 };
9553 
9554 static const Int4 kUnverifiedComment = 0;
9555 static const Int4 kUnverifiedSource = 1;
9556 static const Int4 kUnverifiedSourceAndFeatures = 2;
9557 static const Int4 kChimeraComment = 3;
9558 
9559 static const Int4 kNumStaticIndexerComments = sizeof (kStaticIndexerComments) / sizeof (CharPtr);
9560 static const Int4 kNumStaticIndexerCommentNames = sizeof (kStaticIndexerCommentNames) / sizeof (CharPtr);
9561 
ChangeIndexerCommentPopup(PopuP p)9562 static void ChangeIndexerCommentPopup (PopuP p)
9563 {
9564   AddIndexerCommentFormPtr frm;
9565   Int2 val;
9566 
9567   frm = (AddIndexerCommentFormPtr) GetObjectExtra (p);
9568   if (frm != NULL) {
9569     val = GetValue (p);
9570     if (val > kNumStaticIndexerComments || val == kChimeraComment + 1) {
9571       Show (frm->comment_text);
9572     } else {
9573       Hide (frm->comment_text);
9574     }
9575   }
9576 }
9577 
9578 
DoAddIndexerComments(ButtoN b)9579 static void DoAddIndexerComments (ButtoN b)
9580 {
9581   AddIndexerCommentFormPtr frm;
9582   Int2 val;
9583   AddIndexerCommentData ad;
9584   SeqEntryPtr sep;
9585   CharPtr     tmp;
9586 
9587   frm = (AddIndexerCommentFormPtr) GetObjectExtra (b);
9588   if (frm == NULL) {
9589     return;
9590   }
9591   MemSet (&ad, 0, sizeof (AddIndexerCommentData));
9592   val = GetValue (frm->comment_text_choice);
9593   if (val - 1 == kUnverifiedComment) {
9594     ad.add_unverified_feat = TRUE;
9595   } else if (val - 1 == kUnverifiedSource) {
9596     ad.add_unverified_org = TRUE;
9597   } else if (val - 1 == kUnverifiedSourceAndFeatures) {
9598     ad.add_unverified_feat = TRUE;
9599     ad.add_unverified_org = TRUE;
9600   } else if (val <= kNumStaticIndexerComments) {
9601     ad.comment_text = StringSave (kStaticIndexerComments[val - 1]);
9602     if (val == kChimeraComment + 1 && !TextHasNoText (frm->comment_text)) {
9603       tmp = SaveStringFromText (frm->comment_text);
9604       SetStringValue (&(ad.comment_text), tmp, ExistingTextOption_append_space);
9605       tmp = MemFree (tmp);
9606     }
9607   } else {
9608     ad.comment_text = SaveStringFromText (frm->comment_text);
9609   }
9610   ad.constraint = DialogToPointer (frm->constraint);
9611 
9612   sep = GetTopSeqEntryForEntityID (frm->input_entityID);
9613   VisitBioseqsInSep (sep, &ad, AddIndexerCommentCallback);
9614   ad.comment_text = MemFree (ad.comment_text);
9615   ad.constraint = ConstraintChoiceSetFree (ad.constraint);
9616 
9617   ObjMgrSetDirtyFlag (frm->input_entityID, TRUE);
9618   ObjMgrSendMsg (OM_MSG_UPDATE, frm->input_entityID, 0, 0);
9619   if (!GetStatus(frm->leave_dlg_up)) {
9620     Remove (frm->form);
9621   }
9622   Update ();
9623 }
9624 
9625 
AddIndexerCommentMenuItem(IteM i)9626 static void AddIndexerCommentMenuItem (IteM i)
9627 {
9628   BaseFormPtr  bfp;
9629   AddIndexerCommentFormPtr frm;
9630   Int4 n;
9631   WindoW           w;
9632   GrouP            h, c;
9633   ButtoN           b;
9634 
9635 #ifdef WIN_MAC
9636   bfp = currentFormDataPtr;
9637 #else
9638   bfp = GetObjectExtra (i);
9639 #endif
9640 
9641   frm = (AddIndexerCommentFormPtr) MemNew (sizeof (AddIndexerCommentFormData));
9642   if (frm == NULL) return;
9643 
9644   w = FixedWindow (-50, -33, -10, -10, "Apply Indexer Comments", StdCloseWindowProc);
9645   SetObjectExtra (w, frm, StdCleanupExtraProc);
9646   frm->form = (ForM) w;
9647   frm->input_entityID = bfp->input_entityID;
9648 
9649   h = HiddenGroup (w, -1, 0, NULL);
9650   SetGroupSpacing (h, 10, 10);
9651 
9652   frm->comment_text_choice = PopupList (h, TRUE, ChangeIndexerCommentPopup);
9653   SetObjectExtra (frm->comment_text_choice, frm, NULL);
9654   for (n = 0; n < kNumStaticIndexerComments; n++) {
9655     if (n < kNumStaticIndexerCommentNames && kStaticIndexerCommentNames[n] != NULL) {
9656       PopupItem (frm->comment_text_choice, kStaticIndexerCommentNames[n]);
9657     } else {
9658       PopupItem (frm->comment_text_choice, kStaticIndexerComments[n]);
9659     }
9660   }
9661   PopupItem (frm->comment_text_choice, "Free Text");
9662   frm->comment_text = DialogText (h, "", 15, NULL);
9663   Hide (frm->comment_text);
9664   SetValue (frm->comment_text_choice, kUnverifiedComment + 1);
9665 
9666   frm->constraint = ComplexConstraintDialog (h, NULL, NULL);
9667   ChangeComplexConstraintFieldType (frm->constraint, FieldType_molinfo_field, NULL, Macro_feature_type_any);
9668 
9669   c = HiddenGroup (h, 3, 0, NULL);
9670   b = DefaultButton (c, "Accept", DoAddIndexerComments);
9671   SetObjectExtra (b, frm, NULL);
9672   PushButton (c, "Cancel", StdCancelButtonProc);
9673   frm->leave_dlg_up = CheckBox (c, "Leave Dialog Up", NULL);
9674 
9675   AlignObjects (ALIGN_CENTER, (HANDLE) frm->comment_text_choice,
9676                               (HANDLE) frm->comment_text,
9677                               (HANDLE) frm->constraint,
9678                               (HANDLE) c,
9679                               NULL);
9680   RealizeWindow (w);
9681   Show (w);
9682   Select (w);
9683   Update ();
9684 }
9685 
9686 
RemoveUnverifiedCallback(BioseqPtr bsp,Pointer data)9687 static void RemoveUnverifiedCallback (BioseqPtr bsp, Pointer data)
9688 {
9689   ValNodePtr constraint, vnp;
9690   SeqEntryPtr sep;
9691   Boolean     use_parent = TRUE;
9692   SequenceConstraintPtr sc;
9693 
9694   if (bsp == NULL || ISA_aa(bsp->mol)) {
9695     return;
9696   }
9697 
9698   constraint = (ValNodePtr) data;
9699   if(!DoesObjectMatchConstraintChoiceSet(OBJ_BIOSEQ, bsp, constraint)) {
9700     return;
9701   }
9702   /* if constraint doesn't limit the type of sequence, get best parent */
9703   for (vnp = constraint; vnp != NULL && use_parent; vnp = vnp->next) {
9704     if (vnp->choice == ConstraintChoice_sequence
9705         && (sc = (SequenceConstraintPtr) vnp->data.ptrvalue) != NULL
9706         && sc->seqtype != NULL
9707         && sc->seqtype->choice != SequenceConstraintMolTypeConstraint_any) {
9708       use_parent = FALSE;
9709     }
9710   }
9711   if (use_parent) {
9712     sep = GetBestTopParentForData (bsp->idx.entityID, bsp);
9713   } else {
9714     sep = SeqMgrGetSeqEntryForData (bsp);
9715   }
9716   RemoveUnverifiedUserObjects(sep);
9717 
9718 }
9719 
9720 
DoRemoveUnverified(ButtoN b)9721 static void DoRemoveUnverified (ButtoN b)
9722 {
9723   AddIndexerCommentFormPtr frm;
9724   ValNodePtr constraint;
9725   SeqEntryPtr sep;
9726 
9727   frm = (AddIndexerCommentFormPtr) GetObjectExtra (b);
9728   if (frm == NULL) {
9729     return;
9730   }
9731   constraint = DialogToPointer (frm->constraint);
9732 
9733   sep = GetTopSeqEntryForEntityID (frm->input_entityID);
9734   if (constraint == NULL) {
9735     RemoveUnverifiedUserObjects(sep);
9736   } else {
9737     VisitBioseqsInSep (sep, constraint, RemoveUnverifiedCallback);
9738   }
9739   constraint = ConstraintChoiceSetFree (constraint);
9740 
9741   ObjMgrSetDirtyFlag (frm->input_entityID, TRUE);
9742   ObjMgrSendMsg (OM_MSG_UPDATE, frm->input_entityID, 0, 0);
9743   Remove (frm->form);
9744   Update ();
9745 }
9746 
9747 
RemoveUnverified(IteM i)9748 static void RemoveUnverified (IteM i)
9749 {
9750   BaseFormPtr  bfp;
9751   AddIndexerCommentFormPtr frm;
9752   WindoW           w;
9753   GrouP            h, c;
9754   ButtoN           b;
9755 
9756 #ifdef WIN_MAC
9757   bfp = currentFormDataPtr;
9758 #else
9759   bfp = GetObjectExtra (i);
9760 #endif
9761 
9762   frm = (AddIndexerCommentFormPtr) MemNew (sizeof (AddIndexerCommentFormData));
9763   if (frm == NULL) return;
9764 
9765   w = FixedWindow (-50, -33, -10, -10, "Remove Unverified", StdCloseWindowProc);
9766   SetObjectExtra (w, frm, StdCleanupExtraProc);
9767   frm->form = (ForM) w;
9768   frm->input_entityID = bfp->input_entityID;
9769 
9770   h = HiddenGroup (w, -1, 0, NULL);
9771   SetGroupSpacing (h, 10, 10);
9772 
9773   frm->constraint = ComplexConstraintDialog (h, NULL, NULL);
9774   ChangeComplexConstraintFieldType (frm->constraint, FieldType_molinfo_field, NULL, Macro_feature_type_any);
9775 
9776   c = HiddenGroup (h, 3, 0, NULL);
9777   b = DefaultButton (c, "Accept", DoRemoveUnverified);
9778   SetObjectExtra (b, frm, NULL);
9779   PushButton (c, "Cancel", StdCancelButtonProc);
9780 
9781   AlignObjects (ALIGN_CENTER, (HANDLE) frm->constraint,
9782                               (HANDLE) c,
9783                               NULL);
9784   RealizeWindow (w);
9785   Show (w);
9786   Select (w);
9787   Update ();
9788 }
9789 
9790 
9791 typedef struct convertcdsoptions {
9792   Uint2 featdef_to;
9793   Boolean keep_cds;
9794   Boolean require_internal_stop;
9795   Boolean require_bad_start;
9796   Boolean require_bad_stop;
9797   Boolean require_pseudo;
9798   Boolean require_or;
9799   CharPtr note_fmt;
9800   Boolean remove_mrna;
9801   Boolean remove_gene;
9802   Boolean remove_transcript_id;
9803   Boolean add_comment_descriptor;
9804   ConstraintChoiceSetPtr constraint;
9805 } ConvertCDSOptionsData, PNTR ConvertCDSOptionsPtr;
9806 
9807 static const CharPtr kViralNoteFmt = "nonfunctional %s due to mutation";
9808 static const CharPtr kSimilarNoteFmt = "similar to %s";
9809 
ConvertCDSOptionsNew()9810 static ConvertCDSOptionsPtr ConvertCDSOptionsNew ()
9811 {
9812   ConvertCDSOptionsPtr c;
9813 
9814   c = (ConvertCDSOptionsPtr) MemNew (sizeof (ConvertCDSOptionsData));
9815   c->featdef_to = FEATDEF_misc_feature;
9816   c->keep_cds = FALSE;
9817   c->require_internal_stop = FALSE;
9818   c->require_bad_start = FALSE;
9819   c->require_bad_stop = FALSE;
9820   c->require_pseudo = FALSE;
9821   c->require_or = FALSE;
9822   c->note_fmt = StringSave (kSimilarNoteFmt);
9823   c->remove_mrna = FALSE;
9824   c->remove_gene = FALSE;
9825   c->remove_transcript_id = FALSE;
9826   c->add_comment_descriptor = FALSE;
9827   c->constraint = NULL;
9828   return c;
9829 }
9830 
9831 
ConvertCDSOptionsFree(ConvertCDSOptionsPtr c)9832 static ConvertCDSOptionsPtr ConvertCDSOptionsFree (ConvertCDSOptionsPtr c)
9833 {
9834   if (c != NULL) {
9835     c->note_fmt = MemFree (c->note_fmt);
9836     c->constraint = ConstraintChoiceSetFree (c->constraint);
9837     c = MemFree (c);
9838   }
9839   return c;
9840 }
9841 
9842 
RemoveInappropriateQuals(SeqFeatPtr sfp)9843 static void RemoveInappropriateQuals(SeqFeatPtr sfp)
9844 {
9845     GBQualPtr q, q_prev = NULL, q_next;
9846 
9847     if (sfp == NULL || sfp->qual == NULL) {
9848         return;
9849     }
9850 
9851     for (q = sfp->qual; q != NULL; q = q_next) {
9852         q_next = q->next;
9853         if (StringICmp (q->qual, "transl_table") == 0) {
9854             if (q_prev == NULL) {
9855                 sfp->qual = q_next;
9856             } else {
9857                 q_prev->next = q_next;
9858             }
9859             q->next = NULL;
9860             q = GBQualFree (q);
9861         } else {
9862             q_prev = q;
9863         }
9864     }
9865 }
9866 
9867 
ConvertOneCDS(SeqFeatPtr sfp,Pointer data)9868 static void ConvertOneCDS (SeqFeatPtr sfp, Pointer data)
9869 {
9870   ConvertCDSOptionsPtr c;
9871   SeqFeatPtr           gene = NULL;
9872   SeqMgrFeatContext    context;
9873   SeqFeatPtr           new_sfp = NULL, mrna, protSfp;
9874   GeneRefPtr           grp;
9875   ProtRefPtr           prp = NULL;
9876   ImpFeatPtr           ifp;
9877   CharPtr              prot_name = NULL, prot_desc = NULL, new_comment = NULL, prot_list = NULL;
9878   Int4                 comment_len;
9879   BioseqPtr            protBsp = NULL, nucbsp = NULL;
9880   ValNodePtr           vnp;
9881   Boolean              any_false = FALSE, any_true = FALSE;
9882   SeqLocPtr            new_loc;
9883   Boolean              partial5, partial3;
9884   UserObjectPtr        uop;
9885 
9886   if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION || data == NULL) {
9887     return;
9888   }
9889 
9890   c = (ConvertCDSOptionsPtr) data;
9891 
9892   if (!DoesObjectMatchConstraintChoiceSet (OBJ_SEQFEAT, sfp, c->constraint)) {
9893     return;
9894   }
9895 
9896   /* determine if original feature meets requirements */
9897 
9898   if (!c->require_pseudo && !c->require_internal_stop && !c->require_bad_start && !c->require_bad_stop) {
9899     any_true = TRUE;
9900   } else {
9901     if (c->require_pseudo) {
9902       if (!sfp->pseudo
9903         && ((gene = SeqMgrGetOverlappingGene (sfp->location, &context)) == NULL || !gene->pseudo)) {
9904         any_false = TRUE;
9905       } else {
9906         any_true = TRUE;
9907       }
9908     }
9909     if (c->require_internal_stop) {
9910       if (HasInternalStops(sfp)) {
9911         any_true = TRUE;
9912       } else {
9913         any_false = TRUE;
9914       }
9915     }
9916     if (c->require_bad_start) {
9917       if (HasBadStartCodon(sfp)) {
9918         any_true = TRUE;
9919       } else {
9920         any_false = TRUE;
9921       }
9922     }
9923     if (c->require_bad_stop) {
9924       if (HasBadStopCodon (sfp)) {
9925         any_true = TRUE;
9926       } else {
9927         any_false = TRUE;
9928       }
9929     }
9930   }
9931   if (!any_true) {
9932     return;
9933   } else if (!c->require_or && any_false) {
9934     return;
9935   }
9936 
9937   /* remove mrna if requested */
9938   if (c->remove_mrna) {
9939     mrna = SeqMgrGetOverlappingmRNA (sfp->location, &context);
9940     if (mrna != NULL) {
9941       mrna->idx.deleteme = TRUE;
9942     }
9943   }
9944 
9945   /* remove gene if requested */
9946   if (c->remove_gene) {
9947     if (gene == NULL) {
9948       gene = SeqMgrGetOverlappingGene (sfp->location, &context);
9949     }
9950     if (gene != NULL) {
9951       gene->idx.deleteme = TRUE;
9952     }
9953   }
9954 
9955   /* get Prot-ref before removing transcript ID/marking protein Bioseq for deletion */
9956   protBsp = BioseqFindFromSeqLoc (sfp->product);
9957   protSfp = SeqMgrGetBestProteinFeature (protBsp, &context);
9958   if (protSfp != NULL) {
9959     prp = protSfp->data.value.ptrvalue;
9960   }
9961 
9962   /* add comment descriptor if requested */
9963   if (c->add_comment_descriptor) {
9964     nucbsp = BioseqFindFromSeqLoc (sfp->location);
9965     uop = AddUnverifiedUserObjectToBioseq(nucbsp);
9966     AddStringToUnverifiedUserObject (uop, "Type", "Features");
9967   }
9968 
9969   if (c->featdef_to == FEATDEF_misc_feature) {
9970     if (prp != NULL) {
9971       if (prp->name != NULL && !StringHasNoText (prp->name->data.ptrvalue)) {
9972         prot_name = prp->name->data.ptrvalue;
9973       }
9974       if (!StringHasNoText (prp->desc)) {
9975         prot_desc = prp->desc;
9976       }
9977     }
9978 
9979     if (StringHasNoText (sfp->comment)) {
9980       comment_len = 1;
9981     } else {
9982       comment_len = StringLen (sfp->comment) + 3;
9983     }
9984 
9985     if (prot_name != NULL) {
9986       if (comment_len > 1) {
9987         comment_len += 2;
9988       }
9989       comment_len += StringLen (c->note_fmt) + StringLen (prot_name);
9990     }
9991     if (prot_desc != NULL) {
9992       if (comment_len > 1) {
9993         comment_len += 2;
9994       }
9995       comment_len += StringLen (prot_desc);
9996     }
9997 
9998     if (comment_len > 1) {
9999       new_comment = (CharPtr) MemNew (sizeof (Char) * comment_len);
10000       new_comment[0] = 0;
10001 
10002       if (prot_name != NULL) {
10003         sprintf (new_comment, c->note_fmt, prot_name);
10004       }
10005       if (!StringHasNoText (sfp->comment)) {
10006         if (new_comment[0] != 0) {
10007           StringCat (new_comment, "; ");
10008         }
10009         StringCat (new_comment, sfp->comment);
10010       }
10011       if (prot_desc != NULL) {
10012         if (new_comment[0] != 0) {
10013           StringCat (new_comment, "; ");
10014         }
10015         StringCat (new_comment, prot_desc);
10016       }
10017     }
10018 
10019     if (c->keep_cds) {
10020       new_sfp = CreateNewFeatureOnBioseq (BioseqFindFromSeqLoc (sfp->location), SEQFEAT_IMP, sfp->location);
10021       if (c->remove_transcript_id) {
10022         if (protBsp != NULL) {
10023           protBsp->idx.deleteme = TRUE;
10024         }
10025         sfp->product = SeqLocFree (sfp->product);
10026       }
10027     } else {
10028       new_sfp = sfp;
10029       new_sfp->data.value.ptrvalue = CdRegionFree (new_sfp->data.value.ptrvalue);
10030       new_sfp->data.choice = SEQFEAT_IMP;
10031       /* if we don't keep the CDS, we need to remove the product */
10032       if (protBsp != NULL) {
10033         protBsp->idx.deleteme = TRUE;
10034       }
10035       if (! IsFeatInGPS (sfp) || c->remove_transcript_id) {
10036         sfp->product = SeqLocFree (sfp->product);
10037       }
10038       RemoveInappropriateQuals(sfp);
10039     }
10040     /* for misc_feature, use single interval */
10041     if (new_sfp->location->choice != SEQLOC_INT) {
10042       if (nucbsp == NULL) {
10043         nucbsp = BioseqFindFromSeqLoc (sfp->location);
10044       }
10045       CheckSeqLocForPartial (new_sfp->location, &partial5, &partial3);
10046       new_loc = SeqLocMerge (nucbsp, sfp->location, NULL, TRUE, FALSE, FALSE);
10047       SetSeqLocPartial (new_loc, partial5, partial3);
10048       if (new_loc != NULL && new_loc != sfp->location) {
10049         sfp->location = SeqLocFree (sfp->location);
10050         sfp->location = new_loc;
10051       }
10052     }
10053     ifp = ImpFeatNew ();
10054     new_sfp->data.value.ptrvalue = ifp;
10055     ifp->key = StringSave ("misc_feature");
10056 
10057     new_sfp->comment = MemFree (new_sfp->comment);
10058     new_sfp->comment = new_comment;
10059 
10060     /* set the subtype to zero so that it will be reindexed */
10061     sfp->idx.subtype = 0;
10062   } else {
10063     /* conversion to pseudogene */
10064 
10065     /* find the gene associated with the coding region */
10066     if (gene == NULL) {
10067       gene = SeqMgrGetOverlappingGene (sfp->location, &context);
10068     }
10069 
10070     if (c->keep_cds) {
10071       if (protSfp != NULL) {
10072         /* append protein comment to CDS comment */
10073         if (!StringHasNoText (protSfp->comment)) {
10074           SetStringValue (&(sfp->comment), protSfp->comment, ExistingTextOption_append_semi);
10075         }
10076 
10077         if (prp != NULL) {
10078           /* prepend protein description (if any) to CDS comment */
10079           if (!StringHasNoText (prp->desc)) {
10080             SetStringValue (&(sfp->comment), prp->desc, ExistingTextOption_prefix_semi);
10081           }
10082 
10083           /* Get the protein names and prepend them to the coding region comment or use them to create a gene if one didn't exist */
10084           if (gene == NULL) {
10085             grp = GeneRefNew ();
10086             for (vnp = prp->name; vnp != NULL; vnp = vnp->next) {
10087               SetStringValue (&(grp->desc), vnp->data.ptrvalue, ExistingTextOption_append_semi);
10088             }
10089             gene = CreateNewFeatureOnBioseq (BioseqFindFromSeqLoc (sfp->location), SEQFEAT_GENE, sfp->location);
10090             gene->data.value.ptrvalue = (Pointer) grp;
10091           } else {
10092             for (vnp = prp->name; vnp != NULL; vnp = vnp->next) {
10093               SetStringValue (&(sfp->comment), vnp->data.ptrvalue, ExistingTextOption_prefix_semi);
10094             }
10095           }
10096         }
10097       }
10098       if (protBsp != NULL) {
10099         /* Delete the protein Bioseq that */
10100         /* the CDS points to.             */
10101         protBsp->idx.deleteme = TRUE;
10102       }
10103       /* Mark the CDS as Pseudo */
10104       sfp->pseudo = TRUE;
10105 
10106       if (! IsFeatInGPS (sfp) || c->remove_transcript_id) {
10107         sfp->product = SeqLocFree (sfp->product);
10108       }
10109 
10110       /* Set the subtype to zero so that it will be reindexed */
10111       sfp->idx.subtype = 0;
10112 
10113       /* Mark the overlapping gene as pseudo */
10114       if (gene != NULL) {
10115         gene->pseudo = TRUE;
10116       }
10117     } else {
10118       /* remove CDS */
10119       if (gene == NULL) {
10120         /* need to create gene */
10121         gene = CreateNewFeatureOnBioseq (BioseqFindFromSeqLoc (sfp->location), SEQFEAT_GENE, sfp->location);
10122       }
10123       /* if gene doesn't have generef, create one */
10124       grp = gene->data.value.ptrvalue;
10125       if (grp == NULL) {
10126         grp = GeneRefNew ();
10127         gene->data.value.ptrvalue = grp;
10128       }
10129 
10130       /* mark the gene as pseudo */
10131       gene->pseudo = TRUE;
10132 
10133       /* prepend CDS comment to gene comment */
10134       if (!StringHasNoText (sfp->comment)) {
10135         SetStringValue (&(gene->comment), sfp->comment, ExistingTextOption_prefix_semi);
10136       }
10137 
10138       if (protSfp != NULL) {
10139         /* prepend protein comment to gene comment */
10140         if (!StringHasNoText (protSfp->comment)) {
10141           SetStringValue (&(gene->comment), protSfp->comment, ExistingTextOption_prefix_semi);
10142         }
10143       }
10144 
10145       if (prp != NULL) {
10146         /* prepend protein description to gene comment */
10147         if (!StringHasNoText (prp->desc)) {
10148           SetStringValue (&(gene->comment), prp->desc, ExistingTextOption_prefix_semi);
10149         }
10150         if (StringHasNoText (grp->locus)) {
10151           /* use protein product names for gene locus if gene doesn't already have one */
10152           for (vnp = prp->name; vnp != NULL; vnp = vnp->next) {
10153             SetStringValue (&(grp->locus), vnp->data.ptrvalue, ExistingTextOption_append_semi);
10154           }
10155         } else if (StringHasNoText (grp->desc)) {
10156           /* use protein product names for gene description if gene doesn't already have one */
10157           for (vnp = prp->name; vnp != NULL; vnp = vnp->next) {
10158             SetStringValue (&(grp->desc), vnp->data.ptrvalue, ExistingTextOption_append_semi);
10159           }
10160         } else {
10161           /* prepend list of protein product names to gene comment */
10162           for (vnp = prp->name; vnp != NULL; vnp = vnp->next) {
10163             SetStringValue (&prot_list, vnp->data.ptrvalue, ExistingTextOption_append_semi);
10164           }
10165           SetStringValue (&(gene->comment), prot_list, ExistingTextOption_prefix_semi);
10166           prot_list = MemFree (prot_list);
10167         }
10168       }
10169 
10170       /* Delete the protein Bioseq and */
10171       /* the CDS that points to it.    */
10172       sfp->idx.deleteme = TRUE;
10173       if (protBsp != NULL) {
10174         protBsp->idx.deleteme = TRUE;
10175       }
10176     }
10177   }
10178 }
10179 
10180 
10181 typedef struct convertcdsoptionsdlg {
10182   DIALOG_MESSAGE_BLOCK
10183 
10184   GrouP dest_feat_type;
10185   ButtoN keep_cds;
10186   ButtoN remove_mrna;
10187   ButtoN remove_gene;
10188   ButtoN remove_transcript_id;
10189   GrouP  all_or_conditional;
10190   GrouP  conditions;
10191   ButtoN require_internal_stop;
10192   ButtoN require_bad_start;
10193   ButtoN require_bad_stop;
10194   ButtoN require_pseudo;
10195   GrouP  require_or;
10196   GrouP note_fmt;
10197   ButtoN add_comment_descriptor;
10198   DialoG constraint;
10199 
10200   Nlm_ChangeNotifyProc change_notify;
10201   Pointer              change_userdata;
10202 } ConvertCDSOptionsDlgData, PNTR ConvertCDSOptionsDlgPtr;
10203 
10204 
DataToConvertCDSOptionsDlg(DialoG d,Pointer data)10205 static void DataToConvertCDSOptionsDlg (DialoG d, Pointer data)
10206 {
10207   ConvertCDSOptionsDlgPtr dlg;
10208   ConvertCDSOptionsPtr    c;
10209 
10210   dlg = (ConvertCDSOptionsDlgPtr) GetObjectExtra (d);
10211   if (dlg == NULL) {
10212     return;
10213   }
10214 
10215   c = (ConvertCDSOptionsPtr) data;
10216 
10217   if (c == NULL) {
10218     c = ConvertCDSOptionsNew ();
10219     DataToConvertCDSOptionsDlg (d, c);
10220     c = ConvertCDSOptionsFree (c);
10221   } else {
10222     if (c->featdef_to == FEATDEF_misc_feature) {
10223       SetValue (dlg->dest_feat_type, 1);
10224     } else {
10225       SetValue (dlg->dest_feat_type, 2);
10226     }
10227     SetStatus (dlg->keep_cds, c->keep_cds);
10228     SetStatus (dlg->remove_mrna, c->remove_mrna);
10229     SetStatus (dlg->remove_gene, c->remove_gene);
10230     SetStatus (dlg->remove_transcript_id, c->remove_transcript_id);
10231     SetStatus (dlg->add_comment_descriptor, c->add_comment_descriptor);
10232 
10233     if (!c->require_internal_stop && !c->require_bad_start && !c->require_bad_stop && !c->require_pseudo) {
10234       SetValue (dlg->all_or_conditional, 1);
10235       Disable (dlg->conditions);
10236     } else {
10237       SetValue (dlg->all_or_conditional, 2);
10238       Enable (dlg->conditions);
10239     }
10240     if (c->require_or) {
10241       SetValue (dlg->require_or, 1);
10242     } else {
10243       SetValue (dlg->require_or, 2);
10244     }
10245 
10246     SetStatus (dlg->require_internal_stop, c->require_internal_stop);
10247     SetStatus (dlg->require_bad_start, c->require_bad_start);
10248     SetStatus (dlg->require_bad_stop, c->require_bad_stop);
10249     SetStatus (dlg->require_pseudo, c->require_pseudo);
10250 
10251     if (StringCmp (c->note_fmt, kSimilarNoteFmt) == 0) {
10252       SetValue (dlg->note_fmt, 1);
10253     } else {
10254       SetValue (dlg->note_fmt, 2);
10255     }
10256     PointerToDialog (dlg->constraint, c->constraint);
10257   }
10258   if (dlg->change_notify) {
10259     (dlg->change_notify) (dlg->change_userdata);
10260   }
10261 }
10262 
10263 
DataFromConvertCDSOptionsDlg(DialoG d)10264 static Pointer DataFromConvertCDSOptionsDlg (DialoG d)
10265 {
10266   ConvertCDSOptionsDlgPtr dlg;
10267   ConvertCDSOptionsPtr    c;
10268 
10269   dlg = (ConvertCDSOptionsDlgPtr) GetObjectExtra (d);
10270   if (dlg == NULL) {
10271     return NULL;
10272   }
10273 
10274   c = ConvertCDSOptionsNew();
10275 
10276   if (GetValue (dlg->dest_feat_type) == 1) {
10277     c->featdef_to = FEATDEF_misc_feature;
10278   } else {
10279     c->featdef_to = FEATDEF_GENE;
10280   }
10281   c->keep_cds = GetStatus (dlg->keep_cds);
10282   c->remove_mrna = GetStatus (dlg->remove_mrna);
10283   c->remove_gene = GetStatus (dlg->remove_gene);
10284   c->remove_transcript_id = GetStatus (dlg->remove_transcript_id);
10285   c->add_comment_descriptor = GetStatus (dlg->add_comment_descriptor);
10286 
10287   if (GetValue (dlg->all_or_conditional) == 1) {
10288     c->require_internal_stop = FALSE;
10289     c->require_bad_start = FALSE;
10290     c->require_bad_stop = FALSE;
10291     c->require_pseudo = FALSE;
10292     c->require_or = TRUE;
10293   } else {
10294     c->require_internal_stop = GetStatus (dlg->require_internal_stop);
10295     c->require_bad_start = GetStatus (dlg->require_bad_start);
10296     c->require_bad_stop = GetStatus (dlg->require_bad_stop);
10297     c->require_pseudo = GetStatus (dlg->require_pseudo);
10298     if (GetValue (dlg->require_or) == 1) {
10299       c->require_or = TRUE;
10300     } else {
10301       c->require_or = FALSE;
10302     }
10303   }
10304 
10305   if (GetValue (dlg->note_fmt) == 1) {
10306     c->note_fmt = MemFree (c->note_fmt);
10307     c->note_fmt = StringSave (kSimilarNoteFmt);
10308   } else {
10309     c->note_fmt = MemFree (c->note_fmt);
10310     c->note_fmt = StringSave (kViralNoteFmt);
10311   }
10312 
10313   c->constraint = DialogToPointer (dlg->constraint);
10314   return c;
10315 }
10316 
10317 
TestConvertCDSOptionsDlg(DialoG d)10318 static ValNodePtr TestConvertCDSOptionsDlg (DialoG d)
10319 {
10320   ConvertCDSOptionsDlgPtr dlg;
10321   ValNodePtr err_list = NULL;
10322 
10323   dlg = (ConvertCDSOptionsDlgPtr) GetObjectExtra (d);
10324   if (dlg == NULL) {
10325     return NULL;
10326   }
10327   if (GetValue (dlg->all_or_conditional) == 2) {
10328     if (!GetStatus (dlg->require_internal_stop)
10329         && !GetStatus (dlg->require_bad_start)
10330         && !GetStatus (dlg->require_bad_stop)
10331         && !GetStatus (dlg->require_pseudo)) {
10332       ValNodeAddPointer (&err_list, 0, "no condition");
10333     }
10334   }
10335   return err_list;
10336 }
10337 
10338 
ChangeAllOrConditional(GrouP g)10339 static void ChangeAllOrConditional (GrouP g)
10340 {
10341   ConvertCDSOptionsDlgPtr dlg;
10342 
10343   dlg = (ConvertCDSOptionsDlgPtr) GetObjectExtra (g);
10344   if (dlg == NULL) {
10345     return;
10346   }
10347 
10348   if (GetValue (dlg->all_or_conditional) == 1) {
10349     Disable (dlg->conditions);
10350   } else {
10351     Enable (dlg->conditions);
10352   }
10353   if (dlg->change_notify != NULL) {
10354     (dlg->change_notify) (dlg->change_userdata);
10355   }
10356 }
10357 
10358 
ChangeCDSOptionsButton(ButtoN b)10359 static void ChangeCDSOptionsButton (ButtoN b)
10360 {
10361   ConvertCDSOptionsDlgPtr dlg;
10362 
10363   dlg = (ConvertCDSOptionsDlgPtr) GetObjectExtra (b);
10364   if (dlg == NULL) {
10365     return;
10366   }
10367   if (dlg->change_notify != NULL) {
10368     (dlg->change_notify) (dlg->change_userdata);
10369   }
10370 }
10371 
10372 
ConvertCDSOptionsDialog(GrouP h,Nlm_ChangeNotifyProc change_notify,Pointer change_userdata)10373 static DialoG ConvertCDSOptionsDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
10374 {
10375   ConvertCDSOptionsDlgPtr dlg;
10376   GrouP                   p, g, g2, opts;
10377 
10378   dlg = (ConvertCDSOptionsDlgPtr) MemNew (sizeof (ConvertCDSOptionsDlgData));
10379   if (dlg == NULL)
10380   {
10381     return NULL;
10382   }
10383 
10384   p = HiddenGroup (h, -1, 0, NULL);
10385   SetObjectExtra (p, dlg, StdCleanupExtraProc);
10386 
10387   dlg->dialog = (DialoG) p;
10388   dlg->todialog = DataToConvertCDSOptionsDlg;
10389   dlg->fromdialog = DataFromConvertCDSOptionsDlg;
10390   dlg->dialogmessage = NULL;
10391   dlg->testdialog = TestConvertCDSOptionsDlg;
10392   dlg->change_notify = change_notify;
10393   dlg->change_userdata = change_userdata;
10394 
10395   dlg->dest_feat_type = NormalGroup (p, 2, 0, "Convert to", NULL, NULL);
10396   RadioButton (dlg->dest_feat_type, "misc_feat");
10397   RadioButton (dlg->dest_feat_type, "pseudogene");
10398   SetValue (dlg->dest_feat_type, 1);
10399 
10400   opts = HiddenGroup (p, 0, 4, NULL);
10401   dlg->keep_cds = CheckBox (opts, "Keep original CDS", ChangeCDSOptionsButton);
10402   SetObjectExtra (dlg->keep_cds, dlg, NULL);
10403   dlg->remove_mrna = CheckBox (opts, "Remove overlapping mRNA", ChangeCDSOptionsButton);
10404   SetObjectExtra (dlg->remove_mrna, dlg, NULL);
10405   dlg->remove_gene = CheckBox (opts, "Remove overlapping gene", ChangeCDSOptionsButton);
10406   SetObjectExtra (dlg->remove_gene, dlg, NULL);
10407   dlg->remove_transcript_id = CheckBox (opts, "Remove transcript ID", ChangeCDSOptionsButton);
10408   SetObjectExtra (dlg->remove_transcript_id, dlg, NULL);
10409   dlg->add_comment_descriptor = CheckBox (opts, "Add Unverified", ChangeCDSOptionsButton);
10410 
10411   g = NormalGroup (p, 0, 2, "Conditions", NULL, NULL);
10412   dlg->all_or_conditional = HiddenGroup (g, 0, 2, ChangeAllOrConditional);
10413   RadioButton (dlg->all_or_conditional, "All");
10414   RadioButton (dlg->all_or_conditional, "Where");
10415   SetObjectExtra (dlg->all_or_conditional, dlg, NULL);
10416   SetValue (dlg->all_or_conditional, 1);
10417   g2 = HiddenGroup (g, 2, 0, NULL);
10418   StaticPrompt (g2, "", 10, dialogTextHeight, systemFont, 'l');
10419   dlg->conditions = HiddenGroup (g2, 0, 5, NULL);
10420   dlg->require_internal_stop = CheckBox (dlg->conditions, "CDS has internal stop codon", ChangeCDSOptionsButton);
10421   SetObjectExtra (dlg->require_internal_stop, dlg, NULL);
10422   dlg->require_bad_start = CheckBox (dlg->conditions, "CDS has bad start codon", ChangeCDSOptionsButton);
10423   SetObjectExtra (dlg->require_bad_start, dlg, NULL);
10424   dlg->require_bad_stop = CheckBox (dlg->conditions, "CDS has bad stop codon", ChangeCDSOptionsButton);
10425   SetObjectExtra (dlg->require_bad_stop, dlg, NULL);
10426   dlg->require_pseudo = CheckBox (dlg->conditions, "CDS is pseudo", ChangeCDSOptionsButton);
10427   SetObjectExtra (dlg->require_pseudo, dlg, NULL);
10428   dlg->require_or = HiddenGroup (dlg->conditions, 2, 0, NULL);
10429   RadioButton (dlg->require_or, "OR");
10430   RadioButton (dlg->require_or, "AND");
10431   SetValue (dlg->require_or, 1);
10432   Disable (dlg->conditions);
10433 
10434   dlg->note_fmt = NormalGroup (p, 0, 2, "Comment Format", NULL, NULL);
10435   RadioButton (dlg->note_fmt, "similar to X");
10436   RadioButton (dlg->note_fmt, "nonfunctional X due to mutation");
10437   SetValue (dlg->note_fmt, 1);
10438 
10439   dlg->constraint = ComplexConstraintDialog (p, change_notify, change_userdata);
10440   ChangeComplexConstraintFieldType (dlg->constraint, FieldType_molinfo_field, NULL, Macro_feature_type_any);
10441 
10442   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->dest_feat_type,
10443                               (HANDLE) opts,
10444                               (HANDLE) g,
10445                               (HANDLE) dlg->note_fmt,
10446                               (HANDLE) dlg->constraint,
10447                               NULL);
10448 
10449   return (DialoG) p;
10450 }
10451 
10452 
10453 typedef struct convertcdsfrm {
10454   FORM_MESSAGE_BLOCK
10455   DialoG options;
10456   ButtoN accept_btn;
10457   ButtoN leave_dlg_up;
10458 } ConvertCDSFrmData, PNTR ConvertCDSFrmPtr;
10459 
10460 
EnableCDSConversionAccept(Pointer data)10461 static void EnableCDSConversionAccept (Pointer data)
10462 {
10463   ConvertCDSFrmPtr frm;
10464   ValNodePtr       err_list = NULL;
10465 
10466   frm = (ConvertCDSFrmPtr) data;
10467   if (frm == NULL) {
10468     return;
10469   }
10470   err_list = TestDialog (frm->options);
10471   if (err_list == NULL) {
10472     Enable (frm->accept_btn);
10473   } else {
10474     Disable (frm->accept_btn);
10475   }
10476   err_list = ValNodeFree (err_list);
10477 }
10478 
10479 
DoCDSConversion(ButtoN b)10480 static void DoCDSConversion (ButtoN b)
10481 {
10482   ConvertCDSFrmPtr frm;
10483   SeqEntryPtr      sep;
10484   ConvertCDSOptionsPtr c;
10485 
10486   frm = (ConvertCDSFrmPtr) GetObjectExtra (b);
10487   if (frm == NULL) {
10488     return;
10489   }
10490 
10491   sep = GetTopSeqEntryForEntityID (frm->input_entityID);
10492   c = DialogToPointer (frm->options);
10493   VisitFeaturesInSep (sep, c, ConvertOneCDS);
10494   c = ConvertCDSOptionsFree (c);
10495 
10496   DeleteMarkedObjects (frm->input_entityID, 0, NULL);
10497   RenormalizeNucProtSets (sep, TRUE);
10498 
10499   ObjMgrSetDirtyFlag (frm->input_entityID, TRUE);
10500   ObjMgrSendMsg (OM_MSG_UPDATE, frm->input_entityID, 0, 0);
10501   if (!GetStatus (frm->leave_dlg_up)) {
10502     Remove (frm->form);
10503   }
10504   Update ();
10505 }
10506 
10507 
ConvertCDSBaseForm(BaseFormPtr bfp)10508 static void ConvertCDSBaseForm (BaseFormPtr bfp)
10509 {
10510   ConvertCDSFrmPtr frm;
10511   WindoW           w;
10512   GrouP            h, c;
10513 
10514   if (bfp == NULL) return;
10515 
10516   frm = (ConvertCDSFrmPtr) MemNew (sizeof (ConvertCDSFrmData));
10517   if (frm == NULL) return;
10518 
10519   w = FixedWindow (-50, -33, -10, -10, "Convert CDS", StdCloseWindowProc);
10520   SetObjectExtra (w, frm, StdCleanupExtraProc);
10521   frm->form = (ForM) w;
10522   frm->input_entityID = bfp->input_entityID;
10523 
10524   h = HiddenGroup (w, -1, 0, NULL);
10525   SetGroupSpacing (h, 10, 10);
10526 
10527   frm->options = ConvertCDSOptionsDialog (h, EnableCDSConversionAccept, frm);
10528 
10529   c = HiddenGroup (h, 3, 0, NULL);
10530   frm->accept_btn = DefaultButton (c, "Accept", DoCDSConversion);
10531   SetObjectExtra (frm->accept_btn, frm, NULL);
10532   PushButton (c, "Cancel", StdCancelButtonProc);
10533   frm->leave_dlg_up = CheckBox (c, "Leave dialog up", NULL);
10534 
10535   AlignObjects (ALIGN_CENTER, (HANDLE) frm->options,
10536                               (HANDLE) c,
10537                               NULL);
10538   EnableCDSConversionAccept (frm);
10539   RealizeWindow (w);
10540   Show (w);
10541   Select (w);
10542   Update ();
10543 }
10544 
ConvertCDSMenuItem(IteM i)10545 static void ConvertCDSMenuItem (IteM i)
10546 {
10547   BaseFormPtr  bfp;
10548 
10549 #ifdef WIN_MAC
10550   bfp = currentFormDataPtr;
10551 #else
10552   bfp = GetObjectExtra (i);
10553 #endif
10554   if (bfp == NULL) return;
10555 
10556   ConvertCDSBaseForm (bfp);
10557 }
10558 
ConvertCDSButton(ButtoN b)10559 static void ConvertCDSButton (ButtoN b)
10560 {
10561   BaseFormPtr bfp;
10562 
10563   bfp = GetObjectExtra (b);
10564   if (bfp == NULL) return;
10565 
10566   ConvertCDSBaseForm (bfp);
10567 }
10568 
NewConvertCDSWithInternalStopsToMiscFeat(IteM i)10569 static void NewConvertCDSWithInternalStopsToMiscFeat (IteM i)
10570 {
10571   BaseFormPtr  bfp;
10572   ConvertCDSOptionsPtr o;
10573   SeqEntryPtr sep;
10574 
10575 #ifdef WIN_MAC
10576   bfp = currentFormDataPtr;
10577 #else
10578   bfp = GetObjectExtra (i);
10579 #endif
10580 
10581   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
10582   o = ConvertCDSOptionsNew ();
10583   o->require_internal_stop = TRUE;
10584   o->note_fmt = MemFree (o->note_fmt);
10585   o->note_fmt = StringSave (kSimilarNoteFmt);
10586   VisitFeaturesInSep (sep, o, ConvertOneCDS);
10587   o = ConvertCDSOptionsFree (o);
10588   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
10589   RenormalizeNucProtSets (sep, TRUE);
10590 
10591   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
10592   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
10593   Update ();
10594 }
10595 
NewConvertCDSWithInternalStopsToMiscFeatViral(IteM i)10596 static void NewConvertCDSWithInternalStopsToMiscFeatViral (IteM i)
10597 {
10598   BaseFormPtr  bfp;
10599   ConvertCDSOptionsPtr o;
10600   SeqEntryPtr sep;
10601 
10602 #ifdef WIN_MAC
10603   bfp = currentFormDataPtr;
10604 #else
10605   bfp = GetObjectExtra (i);
10606 #endif
10607 
10608   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
10609   o = ConvertCDSOptionsNew ();
10610   o->require_internal_stop = TRUE;
10611   o->note_fmt = MemFree (o->note_fmt);
10612   o->note_fmt = StringSave (kViralNoteFmt);
10613   VisitFeaturesInSep (sep, o, ConvertOneCDS);
10614   o = ConvertCDSOptionsFree (o);
10615 
10616   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
10617   RenormalizeNucProtSets (sep, TRUE);
10618 
10619   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
10620   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
10621   Update ();
10622 }
10623 
10624 
ConvertCDSWithInternalStopsToMiscFeatWithUnverified(IteM i)10625 static void ConvertCDSWithInternalStopsToMiscFeatWithUnverified (IteM i)
10626 {
10627   BaseFormPtr  bfp;
10628   ConvertCDSOptionsPtr o;
10629   SeqEntryPtr sep;
10630 
10631 #ifdef WIN_MAC
10632   bfp = currentFormDataPtr;
10633 #else
10634   bfp = GetObjectExtra (i);
10635 #endif
10636 
10637   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
10638   o = ConvertCDSOptionsNew ();
10639   o->require_internal_stop = TRUE;
10640   o->note_fmt = MemFree (o->note_fmt);
10641   o->note_fmt = StringSave (kSimilarNoteFmt);
10642   o->add_comment_descriptor = TRUE;
10643   VisitFeaturesInSep (sep, o, ConvertOneCDS);
10644   o = ConvertCDSOptionsFree (o);
10645   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
10646   RenormalizeNucProtSets (sep, TRUE);
10647 
10648   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
10649   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
10650   Update ();
10651 }
10652 
10653 
RemoveTaxonXrefsFromList(ValNodePtr PNTR list)10654 static void RemoveTaxonXrefsFromList (ValNodePtr PNTR list)
10655 {
10656   ValNodePtr vnp, next;
10657   DbtagPtr   dbt;
10658 
10659   if (list == NULL) return;
10660   vnp = *list;
10661   while (vnp != NULL)
10662   {
10663   	next = vnp->next;
10664     dbt = (DbtagPtr) vnp->data.ptrvalue;
10665     if (dbt != NULL && StringICmp ((CharPtr) dbt->db, "taxon") == 0) {
10666       *list = vnp->next;
10667       vnp->next = NULL;
10668       DbtagFree (dbt);
10669       ValNodeFree (vnp);
10670     } else {
10671       list = (ValNodePtr PNTR) &(vnp->next);
10672     }
10673     vnp = next;
10674   }
10675 }
10676 
RemoveTaxonProc(GatherObjectPtr gop)10677 static Boolean RemoveTaxonProc (GatherObjectPtr gop)
10678 
10679 {
10680   BioSourcePtr     biop = NULL;
10681   OrgRefPtr        orp;
10682   ObjValNodePtr    ovn;
10683   SeqDescPtr       sdp;
10684   SeqFeatPtr       sfp;
10685   ValNodePtr       vnp;
10686   BoolPtr          remove_from_biosources;
10687 
10688   switch (gop->itemtype) {
10689     case OBJ_SEQFEAT :
10690       sfp = (SeqFeatPtr) gop->dataptr;
10691       if (sfp != NULL && sfp->idx.subtype == FEATDEF_BIOSRC) {
10692         biop = (BioSourcePtr) sfp->data.value.ptrvalue;
10693       }
10694       RemoveTaxonXrefsFromList (&(sfp->dbxref));
10695       break;
10696     case OBJ_SEQDESC :
10697       sdp = (SeqDescPtr) gop->dataptr;
10698       ovn = (ObjValNodePtr) sdp;
10699       if (sdp != NULL && sdp->extended != 0 && ovn->idx.subtype == Seq_descr_source ) {
10700         biop = (BioSourcePtr) sdp->data.ptrvalue;
10701       }
10702       break;
10703     default :
10704       return TRUE;
10705   }
10706   remove_from_biosources = (BoolPtr) (gop->userdata);
10707   if (!*remove_from_biosources) return TRUE;
10708   if (biop == NULL) return TRUE;
10709   orp = biop->org;
10710   if (orp == NULL) return TRUE;
10711   vnp = orp->db;
10712   if (vnp == NULL) return TRUE;
10713   RemoveTaxonXrefsFromList (&(orp->db));
10714 
10715   return TRUE;
10716 }
10717 
RemoveTaxonXrefs(IteM i,Boolean remove_from_biosources)10718 static void RemoveTaxonXrefs (IteM i, Boolean remove_from_biosources)
10719 
10720 {
10721   BaseFormPtr  bfp;
10722   Boolean      objMgrFilter [OBJ_MAX];
10723   SeqEntryPtr  sep;
10724 
10725 #ifdef WIN_MAC
10726   bfp = currentFormDataPtr;
10727 #else
10728   bfp = GetObjectExtra (i);
10729 #endif
10730   if (bfp == NULL) return;
10731   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
10732   if (sep == NULL) return;
10733 
10734   MemSet ((Pointer) objMgrFilter, FALSE, sizeof (objMgrFilter));
10735   objMgrFilter [OBJ_SEQFEAT] = TRUE;
10736   objMgrFilter [OBJ_SEQDESC] = TRUE;
10737   GatherObjectsInEntity (bfp->input_entityID, 0, NULL,
10738                          RemoveTaxonProc, (Pointer) &remove_from_biosources, objMgrFilter);
10739   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
10740   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
10741   Update ();
10742 }
10743 
RemoveTaxonXrefsFromFeatures(IteM i)10744 static void RemoveTaxonXrefsFromFeatures (IteM i)
10745 {
10746   RemoveTaxonXrefs (i, FALSE);
10747 }
10748 
RemoveTaxonXrefsFromFeaturesAndBioSources(IteM i)10749 static void RemoveTaxonXrefsFromFeaturesAndBioSources (IteM i)
10750 {
10751   RemoveTaxonXrefs (i, TRUE);
10752 }
10753 
10754 /*=========================================================================*/
10755 /*                                                                         */
10756 /* SuppressError_Callback () --                                            */
10757 /*                                                                         */
10758 /*=========================================================================*/
10759 
SuppressError_Callback(SeqFeatPtr sfp,Pointer userdata)10760 static void SuppressError_Callback (SeqFeatPtr sfp, Pointer userdata)
10761 {
10762   GeneRefPtr        grp = NULL;
10763   SeqFeatXrefPtr    xref;
10764   SeqFeatPtr        gene;
10765   SeqMgrFeatContext geneContext;
10766 
10767   /* If we already have a gene xref, then we're OK */
10768 
10769   grp = SeqMgrGetGeneXref (sfp);
10770   if (grp != NULL)
10771     return;
10772 
10773   /* If we have a completely overlapping gene, we're OK */
10774 
10775   gene = SeqMgrGetOverlappingGene (sfp->location, &geneContext);
10776   if (gene != NULL)
10777     return;
10778 
10779   /* If we have a partially overlapping gene */
10780   /* then it is a problem.                   */
10781 
10782   gene = SeqMgrGetOverlappingFeature (sfp->location, FEATDEF_GENE, NULL,
10783 				      0, NULL, SIMPLE_OVERLAP, &geneContext);
10784   if (gene == NULL)
10785     return;
10786 
10787   /* If we got to here, then we have no gene xref and */
10788   /* and a partially overlapping gene, so add on a    */
10789   /* blank gene xref to suppress the error message.   */
10790 
10791   grp = GeneRefNew ();
10792   if (grp != NULL) {
10793     xref = SeqFeatXrefNew ();
10794     xref->data.choice = SEQFEAT_GENE;
10795     xref->data.value.ptrvalue = grp;
10796     xref->next = sfp->xref;
10797     sfp->xref = xref;
10798   }
10799 
10800   /* Return successfully */
10801 
10802   return;
10803 }
10804 
10805 /*=========================================================================*/
10806 /*                                                                         */
10807 /* SuppressCDSGeneRangeError () --                                         */
10808 /*                                                                         */
10809 /*=========================================================================*/
10810 
SuppressCDSGeneRangeError(IteM i)10811 static void SuppressCDSGeneRangeError (IteM i)
10812 
10813 {
10814   BaseFormPtr  bfp;
10815   BioseqPtr    bsp;
10816   Uint2        entityID;
10817   SeqEntryPtr  sep;
10818 
10819   /* Get the Bioseq */
10820 
10821 #ifdef WIN_MAC
10822   bfp = currentFormDataPtr;
10823 #else
10824   bfp = GetObjectExtra (i);
10825 #endif
10826   if (bfp == NULL) return;
10827 
10828   bsp =  GetBioseqGivenIDs (bfp->input_entityID, 1, OBJ_BIOSEQ);
10829   sep = SeqMgrGetSeqEntryForData (bsp);
10830   entityID = ObjMgrGetEntityIDForChoice (sep);
10831   sep = GetTopSeqEntryForEntityID (entityID);
10832 
10833   /* Explore the Bioseq's CDS features, searching for */
10834   /* ones that would generate a CDSGeneRange error.   */
10835 
10836   VisitFeaturesInSep (sep, NULL, SuppressError_Callback);
10837 
10838   /* Force an update and redraw */
10839 
10840   ObjMgrSetDirtyFlag (entityID, TRUE);
10841   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
10842   ArrowCursor ();
10843   Update ();
10844 
10845   /* Return successfully */
10846 
10847   return;
10848 }
10849 
10850 /*=========================================================================*/
10851 /*                                                                         */
10852 /* RestoreError_Callback () --                                             */
10853 /*                                                                         */
10854 /*=========================================================================*/
10855 
RestoreError_Callback(SeqFeatPtr sfp,Pointer userdata)10856 static void RestoreError_Callback (SeqFeatPtr sfp, Pointer userdata)
10857 {
10858   GeneRefPtr        grp = NULL;
10859   SeqFeatPtr        gene;
10860   SeqMgrFeatContext geneContext;
10861 
10862   /* Check for a suppressed gene xref */
10863 
10864   grp = SeqMgrGetGeneXref (sfp);
10865   if (NULL == grp)
10866     return;
10867 
10868   if (FALSE == SeqMgrGeneIsSuppressed (grp))
10869     return;
10870 
10871   /* Check to make sure we don't have a fully overlapping gene */
10872 
10873   gene = SeqMgrGetOverlappingGene (sfp->location, &geneContext);
10874   if (NULL != gene)
10875     return;
10876 
10877   /* If we have a partially overlapping gene */
10878   /* then we need to remove the suppression. */
10879 
10880   gene = SeqMgrGetOverlappingFeature (sfp->location, FEATDEF_GENE, NULL,
10881 				      0, NULL, SIMPLE_OVERLAP, &geneContext);
10882   if (gene == NULL)
10883     return;
10884 
10885   /* If we got to here, then we have a suppressed xref */
10886   /* and a partially overlapping gene, so remove the   */
10887   /* suppression.                                      */
10888 
10889   GeneRefFree (grp);
10890   sfp->xref = SeqFeatXrefFree (sfp->xref);
10891 
10892   /* Return successfully */
10893 
10894   return;
10895 }
10896 
10897 /*=========================================================================*/
10898 /*                                                                         */
10899 /* RestoreCDSGeneRangeError () --                                          */
10900 /*                                                                         */
10901 /*=========================================================================*/
10902 
RestoreCDSGeneRangeError(IteM i)10903 static void RestoreCDSGeneRangeError (IteM i)
10904 
10905 {
10906   BaseFormPtr  bfp;
10907   BioseqPtr    bsp;
10908   Uint2        entityID;
10909   SeqEntryPtr  sep;
10910 
10911   /* Get the Bioseq */
10912 
10913 #ifdef WIN_MAC
10914   bfp = currentFormDataPtr;
10915 #else
10916   bfp = GetObjectExtra (i);
10917 #endif
10918   if (bfp == NULL) return;
10919 
10920   bsp =  GetBioseqGivenIDs (bfp->input_entityID, 1, OBJ_BIOSEQ);
10921   sep = SeqMgrGetSeqEntryForData (bsp);
10922   entityID = ObjMgrGetEntityIDForChoice (sep);
10923   sep = GetTopSeqEntryForEntityID (entityID);
10924 
10925   /* Explore the Bioseq's CDS features, searching for */
10926   /* ones that would generate a CDSGeneRange error.   */
10927 
10928   VisitFeaturesInSep (sep, NULL, RestoreError_Callback);
10929 
10930   /* Force an update and redraw */
10931 
10932   ObjMgrSetDirtyFlag (entityID, TRUE);
10933   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
10934   ArrowCursor ();
10935   Update ();
10936 
10937   /* Return successfully */
10938 
10939   return;
10940 }
10941 
10942 /*-------------------------------------------------------------------------*/
10943 /*                                                                         */
10944 /* SuppressFeatureGeneXref () -- Suppresses any gene xref on the feature   */
10945 /*                               that is passed to it.                     */
10946 /*                                                                         */
10947 /*-------------------------------------------------------------------------*/
10948 
SuppressFeatureGeneXref(SeqFeatPtr sfp)10949 static void SuppressFeatureGeneXref (SeqFeatPtr sfp)
10950 {
10951   GeneRefPtr      grp = NULL;
10952   SeqFeatXrefPtr  xref;
10953 
10954   if (sfp == NULL)
10955   {
10956     return;
10957   }
10958   /* If there is a gene xref, then change it */
10959   /* to a suppression gene xref.             */
10960 
10961   grp = SeqMgrGetGeneXref (sfp);
10962   if (grp != NULL)
10963   {
10964     if (SeqMgrGeneIsSuppressed (grp) == FALSE)
10965 	  {
10966 	    if (NULL != grp->locus)
10967 	    {
10968 	      MemFree(grp->locus);
10969         grp->locus = NULL;
10970 	    }
10971 	    if (NULL != grp->allele)
10972 	    {
10973 	      MemFree(grp->allele);
10974 	      grp->allele = NULL;
10975 	    }
10976 	    if (NULL != grp->desc)
10977 	    {
10978 	      MemFree(grp->desc);
10979 	      grp->desc = NULL;
10980 	    }
10981 	    if (NULL != grp->maploc)
10982       {
10983 	      MemFree (grp->maploc);
10984 	      grp->maploc = NULL;
10985       }
10986       if (NULL != grp->locus_tag)
10987       {
10988         MemFree (grp->locus_tag);
10989         grp->locus_tag = NULL;
10990       }
10991       grp->db  = ValNodeFreeData (grp->db);
10992       grp->syn = ValNodeFreeData (grp->syn);
10993 	  }
10994 	}
10995   /* Otherwise, if there is an overlapping gene, add */
10996   /* a suppression xref for it.                      */
10997   else if (SeqMgrGetOverlappingGene (sfp->location, NULL) != NULL)
10998   {
10999     grp = GeneRefNew ();
11000     if (grp != NULL)
11001     {
11002 	    xref = SeqFeatXrefNew ();
11003 	    xref->data.choice = SEQFEAT_GENE;
11004 	    xref->data.value.ptrvalue = grp;
11005 	    xref->next = sfp->xref;
11006 	    sfp->xref = xref;
11007     }
11008   }
11009 }
11010 
11011 /*=============================================================================*/
11012 /*                                                                             */
11013 /* SuppressGenesOnFeatures () -- Suppress gene xrefs on selected feature types */
11014 /*                                                                             */
11015 /*=============================================================================*/
11016 
11017 typedef struct suppressgenes
11018 {
11019   FORM_MESSAGE_BLOCK
11020   DialoG feature_choice_dlg;
11021   DialoG constraint_dlg;
11022   ButtoN accept_btn;
11023 
11024 } SuppressGenesData, PNTR SuppressGenesPtr;
11025 
SetSuppressGenesAccept(Pointer userdata)11026 static void SetSuppressGenesAccept (Pointer userdata)
11027 {
11028   SuppressGenesPtr dlg;
11029   ValNodePtr       feature_type_list;
11030 
11031   dlg = (SuppressGenesPtr) userdata;
11032   if (dlg == NULL)
11033   {
11034     return;
11035   }
11036   feature_type_list = DialogToPointer (dlg->feature_choice_dlg);
11037   if (feature_type_list == NULL)
11038   {
11039     Disable (dlg->accept_btn);
11040   }
11041   else
11042   {
11043     Enable (dlg->accept_btn);
11044   }
11045   feature_type_list = ValNodeFree (feature_type_list);
11046 }
11047 
SuppressOneGeneOnFeature(SeqFeatPtr sfp,Pointer userdata,FilterSetPtr fsp)11048 static void SuppressOneGeneOnFeature (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
11049 {
11050   SuppressFeatureGeneXref (sfp);
11051 }
11052 
DoSuppressGenesOnFeatures(ButtoN b)11053 static void DoSuppressGenesOnFeatures (ButtoN b)
11054 {
11055   SuppressGenesPtr dlg;
11056   ValNodePtr       feature_type_list, vnp;
11057   FilterSetPtr     fsp;
11058   Uint1            feat_def_choice;
11059   SeqEntryPtr      sep;
11060 
11061   dlg = (SuppressGenesPtr) GetObjectExtra (b);
11062   if (dlg == NULL)
11063   {
11064     return;
11065   }
11066 
11067   sep = GetTopSeqEntryForEntityID (dlg->input_entityID);
11068   if (sep == NULL)
11069   {
11070     return;
11071   }
11072 
11073   feature_type_list = DialogToPointer (dlg->feature_choice_dlg);
11074   if (feature_type_list == NULL)
11075   {
11076     return;
11077   }
11078 
11079   fsp = (FilterSetPtr) DialogToPointer (dlg->constraint_dlg);
11080 
11081   for (vnp = feature_type_list; vnp != NULL; vnp = vnp->next)
11082   {
11083     feat_def_choice = vnp->choice;
11084     if (feat_def_choice == 255)
11085     {
11086       feat_def_choice = 0;
11087     }
11088     OperateOnSeqEntryConstrainedObjects (sep, fsp,
11089                                          SuppressOneGeneOnFeature,
11090                                          NULL, 0, feat_def_choice, 0, dlg);
11091   }
11092 
11093   ValNodeFree (feature_type_list);
11094   FilterSetFree (fsp);
11095 
11096   ObjMgrSetDirtyFlag (dlg->input_entityID, TRUE);
11097   ObjMgrSendMsg (OM_MSG_UPDATE, dlg->input_entityID, 0, 0);
11098   Remove (dlg->form);
11099   Update ();
11100 }
11101 
SuppressGenesOnFeatures(IteM i)11102 static void SuppressGenesOnFeatures (IteM i)
11103 {
11104   BaseFormPtr      bfp;
11105   SuppressGenesPtr dlg;
11106   WindoW           w;
11107   GrouP            h, c;
11108   ButtoN           b;
11109   SeqEntryPtr      sep;
11110 
11111 #ifdef WIN_MAC
11112   bfp = currentFormDataPtr;
11113 #else
11114   bfp = GetObjectExtra (i);
11115 #endif
11116   if (bfp == NULL) return;
11117 
11118   dlg = (SuppressGenesPtr) MemNew (sizeof (SuppressGenesData));
11119   if (dlg == NULL) return;
11120 
11121   w = FixedWindow (-50, -33, -10, -10, "Suppress Genes on Features", StdCloseWindowProc);
11122   SetObjectExtra (w, dlg, StdCleanupExtraProc);
11123   dlg->form = (ForM) w;
11124   dlg->input_entityID = bfp->input_entityID;
11125 
11126   h = HiddenGroup (w, -1, 0, NULL);
11127   SetGroupSpacing (h, 10, 10);
11128 
11129   sep = GetTopSeqEntryForEntityID(bfp->input_entityID);
11130   dlg->feature_choice_dlg = FeatureSelectionDialogEx (h, TRUE, sep, SetSuppressGenesAccept, dlg);
11131   dlg->constraint_dlg = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, FALSE, "Where feature text");
11132 
11133   c = HiddenGroup (h, 2, 0, NULL);
11134   dlg->accept_btn = PushButton (c, "Accept", DoSuppressGenesOnFeatures);
11135   SetObjectExtra (dlg->accept_btn, dlg, NULL);
11136   b = PushButton (c, "Cancel", StdCancelButtonProc);
11137 
11138   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->feature_choice_dlg,
11139                               (HANDLE) dlg->constraint_dlg,
11140                               (HANDLE) c,
11141                               NULL);
11142   RealizeWindow (w);
11143   Show (w);
11144   Select (w);
11145   Update ();
11146 }
11147 
11148 
11149 /*=======================================================================*/
11150 /*                                                                       */
11151 /*  CopyGeneRef () -                                                     */
11152 /*                                                                       */
11153 /*=======================================================================*/
11154 
CopyGeneRef(GeneRefPtr srcGrp)11155 static GeneRefPtr CopyGeneRef (GeneRefPtr srcGrp)
11156 {
11157   GeneRefPtr   destGrp;
11158   DbtagPtr     destDbt;
11159   DbtagPtr     srcDbt;
11160   ValNodePtr   vnp;
11161 
11162   destGrp = GeneRefNew ();
11163 
11164   /* Copy the string fields from source to destination */
11165 
11166   if (srcGrp->locus != NULL)
11167     destGrp->locus = StringSave (srcGrp->locus);
11168 
11169   if (srcGrp->allele != NULL)
11170     destGrp->allele = StringSave (srcGrp->allele);
11171 
11172   if (srcGrp->desc != NULL)
11173     destGrp->desc = StringSave (srcGrp->desc);
11174 
11175   if (srcGrp->maploc != NULL)
11176     destGrp->maploc = StringSave (srcGrp->maploc);
11177 
11178   if (srcGrp->locus_tag != NULL)
11179     destGrp->locus_tag = StringSave (srcGrp->locus_tag);
11180 
11181   /* Copy the DB references */
11182 
11183   destGrp->db = NULL;
11184 
11185   if (srcGrp->db != NULL)
11186     {
11187       vnp = srcGrp->db;
11188       while (vnp != NULL)
11189 	{
11190 	  ValNodeAdd (&(destGrp->db));
11191 	  destDbt = DbtagNew ();
11192 	  srcDbt  = (DbtagPtr) vnp->data.ptrvalue;
11193 	  if (srcDbt != NULL)
11194 	    {
11195 	      if (srcDbt->db != NULL)
11196 		{
11197 		  destDbt->db = (CharPtr) MemNew (sizeof(srcDbt->db));
11198 		  StringCpy (destDbt->db, srcDbt->db);
11199 		}
11200 	      if (srcDbt->tag != NULL)
11201 		{
11202 		  destDbt->tag = ObjectIdNew ();
11203 		  destDbt->tag->id = srcDbt->tag->id;
11204 		  destDbt->tag->str = (CharPtr)MemNew(sizeof(srcDbt->tag->str));
11205 		  StringCpy (destDbt->tag->str, srcDbt->tag->str);
11206 		}
11207 	    }
11208 	  vnp = vnp->next;
11209 	}
11210     }
11211 
11212   /* Copy the synonyms */
11213 
11214   if (srcGrp->syn != NULL)
11215     {
11216       vnp = srcGrp->syn;
11217       while (vnp != NULL)
11218 	{
11219 	  ValNodeCopyStr (&(destGrp->syn), vnp->choice,
11220 			  (CharPtr) vnp->data.ptrvalue);
11221 	  vnp = vnp->next;
11222 	}
11223     }
11224 
11225   /* Return the new gene reference */
11226 
11227   return destGrp;
11228 
11229 }
11230 
ZapRBSGene(SeqFeatPtr sfp,Pointer userdata)11231 static void ZapRBSGene (SeqFeatPtr sfp, Pointer userdata)
11232 
11233 {
11234   Int4               diff;
11235   SeqMgrFeatContext  gcontext;
11236   SeqFeatPtr         gene;
11237   GeneRefPtr         grp;
11238 
11239   if (sfp->idx.subtype != FEATDEF_RBS) return;
11240   grp = SeqMgrGetGeneXref (sfp);
11241   if (grp != NULL && (! SeqMgrGeneIsSuppressed (grp))) return;
11242   gene = SeqMgrGetOverlappingGene (sfp->location, &gcontext);
11243   if (gene == NULL) return;
11244   diff = SeqLocAinB (sfp->location, gene->location);
11245   if (diff == 0) {
11246     gene->idx.deleteme = TRUE;
11247   } else if (diff > 0) {
11248     SeqLocSubtract (gene->location, sfp->location);
11249   }
11250 }
11251 
RemoveRBSGenes(IteM i)11252 static void RemoveRBSGenes (IteM i)
11253 
11254 {
11255   BaseFormPtr  bfp;
11256   SeqEntryPtr  sep;
11257 
11258 #ifdef WIN_MAC
11259   bfp = currentFormDataPtr;
11260 #else
11261   bfp = GetObjectExtra (i);
11262 #endif
11263   if (bfp == NULL) return;
11264   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
11265   if (sep == NULL) return;
11266 
11267   WatchCursor ();
11268   Update ();
11269 
11270   VisitFeaturesInSep (sep, NULL, ZapRBSGene);
11271 
11272   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
11273   SeqMgrClearFeatureIndexes (bfp->input_entityID, NULL);
11274 
11275   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
11276   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
11277   ArrowCursor ();
11278   Update ();
11279 }
11280 
MapFeatToUpOrDownGene(IteM i,Boolean upstream)11281 static void MapFeatToUpOrDownGene (IteM i, Boolean upstream)
11282 
11283 {
11284   BaseFormPtr        bfp;
11285   SeqMgrFeatContext  fcontext;
11286   SeqFeatPtr         gene;
11287   SeqFeatPtr         leftgene;
11288   SeqFeatPtr         rightgene;
11289   SelStructPtr       sel;
11290   SeqEntryPtr        sep;
11291   SeqFeatPtr         sfp;
11292   SelStructPtr       ssp;
11293 
11294 #ifdef WIN_MAC
11295   bfp = currentFormDataPtr;
11296 #else
11297   bfp = GetObjectExtra (i);
11298 #endif
11299   if (bfp == NULL) return;
11300   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
11301   if (sep == NULL) return;
11302 
11303   ssp = ObjMgrGetSelected ();
11304   if (ssp == NULL) return;
11305 
11306   for (sel = ssp; sel != NULL; sel = sel->next) {
11307     if (sel->entityID != bfp->input_entityID) continue;
11308     if (sel->itemtype != OBJ_SEQFEAT) continue;
11309     sfp = SeqMgrGetDesiredFeature (sel->entityID, NULL, sel->itemID, 0, NULL, &fcontext);
11310     if (sfp == NULL) continue;
11311     if (! FindFlankingGenes (sfp->location, &leftgene, &rightgene)) continue;
11312     gene = NULL;
11313     if (upstream) {
11314       gene = leftgene;
11315     } else {
11316       gene = rightgene;
11317     }
11318     if (gene == NULL) continue;
11319 
11320     AssignGeneXrefToFeat (sfp, gene);
11321   }
11322 
11323   ObjMgrSelect (0, 0, 0, 0, NULL);
11324 
11325   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
11326   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
11327 
11328 }
11329 
MapFeatToUpstreamGene(IteM i)11330 static void MapFeatToUpstreamGene (IteM i)
11331 
11332 {
11333   MapFeatToUpOrDownGene (i, TRUE);
11334 }
11335 
MapFeatToDownstreamGene(IteM i)11336 static void MapFeatToDownstreamGene (IteM i)
11337 
11338 {
11339   MapFeatToUpOrDownGene (i, FALSE);
11340 }
11341 
11342 
MarkBankitComments(GatherObjectPtr gop)11343 static Boolean MarkBankitComments (GatherObjectPtr gop)
11344 
11345 {
11346   ObjectIdPtr    oip;
11347   ObjValNodePtr  ovn;
11348   SeqDescrPtr    sdp;
11349   UserObjectPtr  uop;
11350 
11351   if (gop == NULL || gop->itemtype != OBJ_SEQDESC) return TRUE;
11352   sdp = (SeqDescrPtr) gop->dataptr;
11353   if (sdp == NULL || sdp->choice != Seq_descr_user || sdp->extended == 0) return TRUE;
11354   uop = (UserObjectPtr) sdp->data.ptrvalue;
11355   if (uop == NULL) return TRUE;
11356   oip = uop->type;
11357   if (oip == NULL || StringCmp (oip->str, "Submission") != 0) return TRUE;
11358   ovn = (ObjValNodePtr) sdp;
11359   ovn->idx.deleteme = TRUE;
11360   return TRUE;
11361 }
11362 
RemoveBankitComments(IteM i)11363 static void RemoveBankitComments (IteM i)
11364 
11365 {
11366   BaseFormPtr  bfp;
11367   Boolean      objMgrFilter [OBJ_MAX];
11368   SeqEntryPtr  sep;
11369 
11370 #ifdef WIN_MAC
11371   bfp = currentFormDataPtr;
11372 #else
11373   bfp = GetObjectExtra (i);
11374 #endif
11375   if (bfp == NULL) return;
11376   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
11377   if (sep == NULL) return;
11378 
11379   MemSet ((Pointer) objMgrFilter, FALSE, sizeof (objMgrFilter));
11380   objMgrFilter [OBJ_SEQDESC] = TRUE;
11381   GatherObjectsInEntity (bfp->input_entityID, 0, NULL,
11382                          MarkBankitComments, NULL, objMgrFilter);
11383   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
11384   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
11385   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
11386 }
11387 
11388 
SkipCommentDescriptor(CharPtr text)11389 static Boolean SkipCommentDescriptor (CharPtr text)
11390 {
11391   if (StringHasNoText (text)) {
11392     return TRUE;
11393   } else if (StringNICmp (text, "LocalID:", 8) == 0) {
11394     return TRUE;
11395   } else if (StringNICmp (text, "BankIt ID:", 10) == 0) {
11396     return TRUE;
11397   } else if (StringNICmp (text, "bankit", 6) == 0 && StringIsAllDigits(text + 6)) {
11398     return TRUE;
11399   } else {
11400     return FALSE;
11401   }
11402 }
11403 
11404 
DoCopyBankItComments(SeqDescrPtr sdp,Pointer userdata)11405 static void DoCopyBankItComments (SeqDescrPtr sdp, Pointer userdata)
11406 
11407 {
11408   ObjectIdPtr    oip;
11409   CharPtr        str;
11410   UserFieldPtr   ufp;
11411   UserObjectPtr  uop;
11412   SeqDescrPtr    vnp;
11413 
11414   if (sdp == NULL || sdp->choice != Seq_descr_user || sdp->extended == 0) return;
11415   uop = (UserObjectPtr) sdp->data.ptrvalue;
11416   if (uop == NULL) return;
11417   oip = uop->type;
11418   if (oip == NULL || StringCmp (oip->str, "Submission") != 0) return;
11419 
11420   for (ufp = uop->data; ufp != NULL; ufp = ufp->next) {
11421     oip = ufp->label;
11422     if (oip != NULL && StringCmp (oip->str, "AdditionalComment") == 0) {
11423       str = ufp->data.ptrvalue;
11424       if (! SkipCommentDescriptor (str)) {
11425         vnp = SeqDescrNew (NULL);
11426         if (vnp != NULL) {
11427           vnp->choice = Seq_descr_comment;
11428           vnp->data.ptrvalue = StringSave (str);
11429           vnp->next = sdp->next;
11430           sdp->next = vnp;
11431         }
11432       }
11433     }
11434   }
11435 
11436 }
11437 
CopyBankitComments(IteM i)11438 static void CopyBankitComments (IteM i)
11439 
11440 {
11441   BaseFormPtr  bfp;
11442   SeqEntryPtr  sep;
11443 
11444 #ifdef WIN_MAC
11445   bfp = currentFormDataPtr;
11446 #else
11447   bfp = GetObjectExtra (i);
11448 #endif
11449   if (bfp == NULL) return;
11450   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
11451   if (sep == NULL) return;
11452 
11453   VisitDescriptorsInSep (sep, NULL, DoCopyBankItComments);
11454 
11455   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
11456   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
11457 }
11458 
ENUM_ALIST(molinfo_biomol_alist)11459 static ENUM_ALIST(molinfo_biomol_alist)
11460   {"Any",                  254},
11461   {" ",                      0},
11462   {"Genomic DNA or RNA",     1},
11463   {"Precursor RNA",          2},
11464   {"mRNA [cDNA]",            3},
11465   {"Ribosomal RNA",          4},
11466   {"Transfer RNA",           5},
11467   {"Peptide",                8},
11468   {"Other-Genetic",          9},
11469   {"Genomic-mRNA",          10},
11470   {"cRNA",                  11},
11471   {"Transcribed RNA",       13},
11472   {"Other",                255},
11473 END_ENUM_ALIST
11474 
11475 static ENUM_ALIST(molinfo_tech_alist)
11476   {"Any",               254},
11477   {" ",                   0},
11478   {"Standard",            1},
11479   {"EST",                 2},
11480   {"STS",                 3},
11481   {"Survey",              4},
11482   {"Genetic Map",         5},
11483   {"Physical Map",        6},
11484   {"Derived",             7},
11485   {"Concept-Trans",       8},
11486   {"Seq-Pept",            9},
11487   {"Both",               10},
11488   {"Seq-Pept-Overlap",   11},
11489   {"Seq-Pept-Homol",     12},
11490   {"Concept-Trans-A",    13},
11491   {"HTGS 0",             18},
11492   {"HTGS 1",             14},
11493   {"HTGS 2",             15},
11494   {"HTGS 3",             16},
11495   {"FLI_cDNA",           17},
11496   {"HTC",                19},
11497   {"WGS",                20},
11498   {"Barcode",            21},
11499   {"Composite-WGS-HTGS", 22},
11500   {"TSA",                MI_TECH_tsa},
11501   {"Other:",            255},
11502 END_ENUM_ALIST
11503 
11504 static ENUM_ALIST(molinfo_complete_alist)
11505   {"Any",     254},
11506   {" ",         0},
11507   {"Complete",  1},
11508   {"Partial",   2},
11509   {"No Left",   3},
11510   {"No Right",  4},
11511   {"No Ends",   5},
11512   {"Other",   255},
11513 END_ENUM_ALIST
11514 
11515 static ENUM_ALIST(mol_alist)
11516 {"Any",             Seq_mol_other - 1},
11517 {" ",               0},
11518 {"DNA",             Seq_mol_dna},
11519 {"RNA",             Seq_mol_rna},
11520 {"Protein",         Seq_mol_aa},
11521 {"Nucleotide",      Seq_mol_na},
11522 {"Other",           Seq_mol_other},
11523 END_ENUM_ALIST
11524 
11525 static ENUM_ALIST(topology_alist)
11526 {"Any",             254},
11527 {" ",               0},
11528 {"Linear",          TOPOLOGY_LINEAR},
11529 {"Circular",        TOPOLOGY_CIRCULAR},
11530 {"Tandem",          TOPOLOGY_TANDEM},
11531 {"Other",           255},
11532 END_ENUM_ALIST
11533 
11534 static ENUM_ALIST(strand_alist)
11535 {"Any",             254},
11536 {" ",               Seq_strand_unknown},
11537 {"Single",          Seq_strand_plus},
11538 {"Double",          Seq_strand_minus},
11539 {"Mixed",           Seq_strand_both},
11540 {"Mixed Rev",       Seq_strand_both_rev},
11541 {"Other",           Seq_strand_other},
11542 END_ENUM_ALIST
11543 
11544 static ValNodePtr MakeValNodeListFromEnum ( EnumFieldAssocPtr al)
11545 {
11546   EnumFieldAssocPtr efap;
11547   ValNodePtr        list;
11548 
11549   efap = al;
11550   list = NULL;
11551   while (efap->name != NULL)
11552   {
11553     ValNodeAddStr (&list, efap->value, StringSave (efap->name));
11554     efap ++;
11555   }
11556   return list;
11557 }
11558 
ReplaceValNodeString(ValNodePtr list,CharPtr find,CharPtr repl)11559 static void ReplaceValNodeString (ValNodePtr list, CharPtr find, CharPtr repl)
11560 {
11561   ValNodePtr vnp;
11562 
11563   if (list == NULL || find == NULL || repl == NULL) return;
11564 
11565   for (vnp = list; vnp != NULL; vnp = vnp->next)
11566   {
11567     if (StringCmp (vnp->data.ptrvalue, find) == 0)
11568     {
11569       MemFree (vnp->data.ptrvalue);
11570       vnp->data.ptrvalue = StringSave (repl);
11571     }
11572   }
11573 }
11574 
InitValNodePopup(ValNodePtr list,PopuP p)11575 extern void InitValNodePopup (ValNodePtr list, PopuP p)
11576 {
11577   ValNodePtr vnp;
11578 
11579   for (vnp = list; vnp != NULL; vnp = vnp->next)
11580   {
11581     if (vnp->data.ptrvalue != NULL)
11582     {
11583       PopupItem (p, vnp->data.ptrvalue);
11584     }
11585   }
11586 }
11587 
GetValNodePopup(PopuP p,ValNodePtr list)11588 extern Int2 GetValNodePopup (PopuP p, ValNodePtr list)
11589 {
11590   ValNodePtr vnp;
11591   Int2       popupval;
11592 
11593   popupval = GetValue (p);
11594   if (popupval == 0)
11595   {
11596     return -1;
11597   }
11598   for (vnp = list; vnp != NULL && popupval > 1; vnp = vnp->next)
11599   {
11600     if (vnp->data.ptrvalue != NULL)
11601     {
11602       popupval --;
11603     }
11604   }
11605   if (popupval > 1 || vnp == NULL) return -1;
11606   return vnp->choice;
11607 }
11608 
SetValNodePopupValue(ValNodePtr list,PopuP p,CharPtr val)11609 extern void SetValNodePopupValue (ValNodePtr list, PopuP p, CharPtr val)
11610 {
11611   ValNodePtr vnp;
11612   Int2       popupval;
11613 
11614   popupval = 1;
11615   for (vnp = list; vnp != NULL; vnp = vnp->next)
11616   {
11617     if (vnp->data.ptrvalue != NULL)
11618     {
11619       if (StringCmp (vnp->data.ptrvalue, val) == 0)
11620       {
11621         SetValue (p, popupval);
11622       }
11623       popupval ++;
11624     }
11625   }
11626 }
11627 
11628 typedef struct molinfoblockx {
11629   PopuP           moltype;
11630   ValNodePtr      moltype_values;
11631   PopuP           technique;
11632   ValNodePtr      technique_values;
11633   PopuP           complete;
11634   ValNodePtr      complete_values;
11635   PopuP           molPopup;
11636   ValNodePtr      mol_values;
11637   PopuP           topologyPopup;
11638   ValNodePtr      topology_values;
11639   PopuP           strandPopup;
11640   ValNodePtr      strand_values;
11641 } MolInfoBlock, PNTR MolInfoBlockPtr;
11642 
FreeMolInfoBlockData(MolInfoBlockPtr mibp)11643 static void FreeMolInfoBlockData (MolInfoBlockPtr mibp)
11644 {
11645   if (mibp == NULL) return;
11646   ValNodeFreeData (mibp->moltype_values);
11647   mibp->moltype_values = NULL;
11648   ValNodeFreeData (mibp->technique_values);
11649   mibp->technique_values = NULL;
11650   ValNodeFreeData (mibp->complete_values);
11651   mibp->complete_values = NULL;
11652   ValNodeFreeData (mibp->mol_values);
11653   mibp->mol_values = NULL;
11654   ValNodeFreeData (mibp->topology_values);
11655   mibp->topology_values = NULL;
11656   ValNodeFreeData (mibp->strand_values);
11657   mibp->strand_values = NULL;
11658 }
11659 
11660 
SequenceConstraintXFree(SequenceConstraintXPtr scp)11661 extern SequenceConstraintXPtr SequenceConstraintXFree (SequenceConstraintXPtr scp)
11662 {
11663   if (scp != NULL)
11664   {
11665     scp->string_constraint = StringConstraintXFree (scp->string_constraint);
11666     scp->source_constraint = ChoiceConstraintFree (scp->source_constraint);
11667     scp->feature_list = ValNodeFree (scp->feature_list);
11668     scp = MemFree (scp);
11669   }
11670   return scp;
11671 }
11672 
11673 
11674 typedef struct sequenceconstraintdlg
11675 {
11676   DIALOG_MESSAGE_BLOCK
11677   GrouP  seq_type_constraint;
11678   GrouP  other_constraint_type;
11679   DialoG source_constraint;
11680   DialoG feature_list;
11681   DialoG feature_string_constraint;
11682   DialoG id_string_constraint;
11683 
11684 } SequenceConstraintXDlgData, PNTR SequenceConstraintXDlgPtr;
11685 
11686 
11687 enum sequenceconstraintothertype
11688 {
11689   SEQ_CONSTRAINT_ANY = 0,
11690   SEQ_CONSTRAINT_SOURCE,
11691   SEQ_CONSTRAINT_FEATURE_TEXT,
11692   SEQ_CONSTRAINT_ID
11693 };
11694 
11695 
ChangeSequenceConstraintXType(GrouP g)11696 static void ChangeSequenceConstraintXType (GrouP g)
11697 {
11698   SequenceConstraintXDlgPtr scdp;
11699   Int4                     other_constraint_type;
11700 
11701   scdp = (SequenceConstraintXDlgPtr) GetObjectExtra (g);
11702   if (scdp == NULL)
11703   {
11704     return;
11705   }
11706   other_constraint_type = (GetValue (scdp->other_constraint_type) - 1) / 2;
11707   Disable (scdp->source_constraint);
11708   Disable (scdp->feature_string_constraint);
11709   Disable (scdp->id_string_constraint);
11710   if (other_constraint_type == SEQ_CONSTRAINT_SOURCE)
11711   {
11712     Enable (scdp->source_constraint);
11713   }
11714   else if (other_constraint_type == SEQ_CONSTRAINT_FEATURE_TEXT)
11715   {
11716     Enable (scdp->feature_string_constraint);
11717   }
11718   else if (other_constraint_type == SEQ_CONSTRAINT_ID)
11719   {
11720     Enable (scdp->id_string_constraint);
11721   }
11722 }
11723 
ResetSequenceConstraintXDialog(DialoG d)11724 static void ResetSequenceConstraintXDialog (DialoG d)
11725 {
11726   SequenceConstraintXDlgPtr scdp;
11727 
11728   scdp = (SequenceConstraintXDlgPtr) GetObjectExtra (d);
11729   if (scdp == NULL)
11730   {
11731     return;
11732   }
11733 
11734   SetValue (scdp->seq_type_constraint, 1);
11735   SetValue (scdp->other_constraint_type, SEQ_CONSTRAINT_ANY + 1);
11736   ChangeSequenceConstraintXType (scdp->other_constraint_type);
11737 }
11738 
SequenceConstraintXToDialog(DialoG d,Pointer data)11739 static void SequenceConstraintXToDialog (DialoG d, Pointer data)
11740 {
11741   SequenceConstraintXPtr    scp;
11742   SequenceConstraintXDlgPtr scdp;
11743 
11744   scdp = (SequenceConstraintXDlgPtr) GetObjectExtra (d);
11745   if (scdp == NULL)
11746   {
11747     return;
11748   }
11749 
11750   scp = (SequenceConstraintXPtr) data;
11751 
11752   if (scp == NULL)
11753   {
11754     ResetSequenceConstraintXDialog (d);
11755   }
11756   else
11757   {
11758     if (scp->nucs_ok && scp->prots_ok)
11759     {
11760       SetValue (scdp->seq_type_constraint, 1);
11761     }
11762     else if (scp->nucs_ok)
11763     {
11764       SetValue (scdp->seq_type_constraint, 2);
11765     }
11766     else
11767     {
11768       SetValue (scdp->seq_type_constraint, 3);
11769     }
11770     SetValue (scdp->other_constraint_type, scp->other_constraint_type + 1);
11771     switch (scp->other_constraint_type)
11772     {
11773       case SEQ_CONSTRAINT_SOURCE:
11774           PointerToDialog (scdp->source_constraint, scp->source_constraint);
11775           break;
11776       case SEQ_CONSTRAINT_FEATURE_TEXT:
11777           PointerToDialog (scdp->feature_string_constraint, scp->string_constraint);
11778           PointerToDialog (scdp->feature_list, scp->feature_list);
11779           break;
11780       case SEQ_CONSTRAINT_ID:
11781           PointerToDialog (scdp->id_string_constraint, scp->string_constraint);
11782           break;
11783     }
11784     ChangeSequenceConstraintXType (scdp->other_constraint_type);
11785   }
11786 }
11787 
11788 
DialogToSequenceConstraintX(DialoG d)11789 static Pointer DialogToSequenceConstraintX (DialoG d)
11790 {
11791   SequenceConstraintXPtr    scp;
11792   SequenceConstraintXDlgPtr scdp;
11793 
11794   scdp = (SequenceConstraintXDlgPtr) GetObjectExtra (d);
11795   if (scdp == NULL)
11796   {
11797     return NULL;
11798   }
11799 
11800   scp = (SequenceConstraintXPtr) MemNew (sizeof (SequenceConstraintXData));
11801   if (scp != NULL)
11802   {
11803     switch (GetValue (scdp->seq_type_constraint))
11804     {
11805       case 1:
11806         scp->nucs_ok = TRUE;
11807         scp->prots_ok = TRUE;
11808         break;
11809       case 2:
11810         scp->nucs_ok = TRUE;
11811         break;
11812       case 3:
11813         scp->prots_ok = TRUE;
11814         break;
11815     }
11816 
11817     scp->other_constraint_type = (GetValue (scdp->other_constraint_type) - 1)/2;
11818     switch (scp->other_constraint_type)
11819     {
11820       case SEQ_CONSTRAINT_SOURCE:
11821         scp->source_constraint = DialogToPointer (scdp->source_constraint);
11822         break;
11823       case SEQ_CONSTRAINT_FEATURE_TEXT:
11824         scp->string_constraint = DialogToPointer (scdp->feature_string_constraint);
11825         scp->feature_list = DialogToPointer (scdp->feature_list);
11826         break;
11827       case SEQ_CONSTRAINT_ID:
11828         scp->string_constraint = DialogToPointer (scdp->id_string_constraint);
11829         break;
11830     }
11831   }
11832   return scp;
11833 }
11834 
11835 
SequenceConstraintXMessage(DialoG d,Int2 mssg)11836 static void SequenceConstraintXMessage (DialoG d, Int2 mssg)
11837 
11838 {
11839   SequenceConstraintXDlgPtr scdp;
11840 
11841   scdp = (SequenceConstraintXDlgPtr) GetObjectExtra (d);
11842   if (scdp != NULL) {
11843     switch (mssg) {
11844       case VIB_MSG_INIT :
11845         ResetSequenceConstraintXDialog (d);
11846         break;
11847       case VIB_MSG_ENTER :
11848         Select (scdp->other_constraint_type);
11849         break;
11850       default :
11851         break;
11852     }
11853   }
11854 }
11855 
TestSequenceConstraintXDialog(DialoG d)11856 static ValNodePtr TestSequenceConstraintXDialog (DialoG d)
11857 
11858 {
11859   return NULL;
11860 }
11861 
11862 
SequenceConstraintXDialog(GrouP g)11863 extern DialoG SequenceConstraintXDialog (GrouP g)
11864 {
11865   SequenceConstraintXDlgPtr dlg;
11866   GrouP p, k;
11867 
11868   dlg = (SequenceConstraintXDlgPtr) MemNew (sizeof (SequenceConstraintXDlgData));
11869   if (dlg == NULL) return NULL;
11870 
11871   p = HiddenGroup (g, -1, 0, NULL);
11872   SetObjectExtra (p, dlg, StdCleanupExtraProc);
11873   SetGroupSpacing (p, 10, 10);
11874 
11875   dlg->dialog = (DialoG) p;
11876   dlg->todialog = SequenceConstraintXToDialog;
11877   dlg->fromdialog = DialogToSequenceConstraintX;
11878   dlg->dialogmessage = SequenceConstraintXMessage;
11879   dlg->testdialog = TestSequenceConstraintXDialog;
11880 
11881   dlg->seq_type_constraint = HiddenGroup (p, 4, 0, NULL);
11882   RadioButton (dlg->seq_type_constraint, "All Sequences");
11883   RadioButton (dlg->seq_type_constraint, "Nucleotides");
11884   RadioButton (dlg->seq_type_constraint, "Proteins");
11885   SetValue (dlg->seq_type_constraint, 2);
11886 
11887   dlg->other_constraint_type = HiddenGroup (p, 2, 0, ChangeSequenceConstraintXType);
11888   RadioButton (dlg->other_constraint_type, "Any sequence");
11889   StaticPrompt (dlg->other_constraint_type, "", 0, dialogTextHeight, systemFont, 'l');
11890 
11891   RadioButton (dlg->other_constraint_type, "Where sequence source");
11892   dlg->source_constraint = SourceConstraintDialogX (dlg->other_constraint_type, FALSE);
11893 
11894   RadioButton (dlg->other_constraint_type, "Where feature text");
11895   k = HiddenGroup (dlg->other_constraint_type, 2, 0, NULL);
11896   SetGroupSpacing (k, 10, 10);
11897   dlg->feature_list = FeatureSelectionDialog (k, TRUE, NULL, NULL);
11898   dlg->feature_string_constraint = StringConstraintDialogX (k, NULL, FALSE);
11899 
11900   RadioButton (dlg->other_constraint_type, "Where sequence ID");
11901   dlg->id_string_constraint = StringConstraintDialogX (dlg->other_constraint_type, NULL, FALSE);
11902 
11903   SetValue (dlg->other_constraint_type, CHOICE_CONSTRAINT_ANY);
11904   SetObjectExtra (dlg->other_constraint_type, dlg, NULL);
11905 
11906   Disable (dlg->source_constraint);
11907   Disable (dlg->feature_string_constraint);
11908   Disable (dlg->id_string_constraint);
11909 
11910   AlignObjects (ALIGN_CENTER, (HANDLE) dlg->seq_type_constraint,
11911                               (HANDLE) dlg->other_constraint_type, NULL);
11912 
11913   return (DialoG) p;
11914 
11915 }
11916 
11917 
DoesIDListMeetStringConstraint(SeqIdPtr sip,StringConstraintXPtr string_constraint)11918 extern Boolean DoesIDListMeetStringConstraint (SeqIdPtr sip, StringConstraintXPtr string_constraint)
11919 {
11920   Char       id [41];
11921   CharPtr    cp, cp_dst;
11922   SeqIdPtr   tmp;
11923   Boolean    match, changed;
11924 
11925   if (sip == NULL)
11926   {
11927     return FALSE;
11928   }
11929   if (string_constraint == NULL)
11930   {
11931     return TRUE;
11932   }
11933 
11934   while (sip != NULL)
11935   {
11936     /* temporary disconnect ID from list */
11937     tmp = sip->next;
11938     sip->next = NULL;
11939     id [0] = '\0';
11940     SeqIdWrite (sip, id, PRINTID_REPORT, sizeof (id) - 1);
11941     match = DoesStringMatchConstraintX (id, string_constraint);
11942     if (!match)
11943     {
11944       changed = FALSE;
11945       /* remove terminating pipe character */
11946       if (id[StringLen(id) - 1] == '|')
11947       {
11948         id[StringLen(id) - 1] = 0;
11949         changed = TRUE;
11950       }
11951       /* remove leading pipe identifier */
11952       cp = StringChr (id, '|');
11953       if (cp != NULL)
11954       {
11955         changed = TRUE;
11956         cp++;
11957         cp_dst = id;
11958         while (*cp != 0)
11959         {
11960           *cp_dst = *cp;
11961           cp_dst++;
11962           cp++;
11963         }
11964         *cp_dst = 0;
11965       }
11966       if (changed)
11967       {
11968         match = DoesStringMatchConstraintX (id, string_constraint);
11969       }
11970 
11971       /* if search text doesn't have ., try ID without version */
11972       if (!match && StringChr (string_constraint->match_text, '.') == NULL)
11973       {
11974         cp = StringChr (id, '.');
11975         if (cp != NULL)
11976         {
11977           *cp = 0;
11978           match = DoesStringMatchConstraintX (id, string_constraint);
11979         }
11980       }
11981     }
11982     sip->next = tmp;
11983 
11984     if (match)
11985     {
11986       if (string_constraint->not_present)
11987       {
11988         return FALSE;
11989       }
11990       else
11991       {
11992         return TRUE;
11993       }
11994     }
11995     sip = sip->next;
11996   }
11997   if (string_constraint->not_present)
11998   {
11999     return TRUE;
12000   }
12001   else
12002   {
12003     return FALSE;
12004   }
12005 }
12006 
12007 
DoesSequenceMatchSequenceConstraintX(BioseqPtr bsp,SequenceConstraintXPtr scp)12008 extern Boolean DoesSequenceMatchSequenceConstraintX (BioseqPtr bsp, SequenceConstraintXPtr scp)
12009 {
12010   SeqDescrPtr       sdp;
12011   SeqMgrDescContext dcontext;
12012 
12013   if (bsp == NULL) return FALSE;
12014   if (scp == NULL) return TRUE;
12015   if (!scp->nucs_ok && ISA_na (bsp->mol)) return FALSE;
12016   if (!scp->prots_ok && ISA_aa (bsp->mol)) return FALSE;
12017   switch (scp->other_constraint_type)
12018   {
12019     case SEQ_CONSTRAINT_ANY:
12020       return TRUE;
12021       break;
12022     case SEQ_CONSTRAINT_SOURCE:
12023       sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &dcontext);
12024       if (sdp != NULL)
12025       {
12026         return DoesOneSourceMatchConstraint(sdp->data.ptrvalue, scp->source_constraint);
12027       }
12028       break;
12029     case SEQ_CONSTRAINT_FEATURE_TEXT:
12030       return DoBioseqFeaturesMatchSequenceConstraintX (bsp, scp->feature_list, scp->string_constraint);
12031       break;
12032     case SEQ_CONSTRAINT_ID:
12033       return DoesIDListMeetStringConstraint(bsp->id, scp->string_constraint);
12034       break;
12035   }
12036   return FALSE;
12037 }
12038 
12039 typedef struct molinfoedit {
12040   DESCRIPTOR_FORM_BLOCK
12041   SeqEntryPtr     sep;
12042   MolInfoBlock    from;
12043   MolInfoBlock    to;
12044   DialoG          sequence_constraint;
12045   SequenceConstraintXPtr scp;
12046   Boolean               allow_existing;
12047 } MolInfoEdit, PNTR MolInfoEditPtr;
12048 
12049 static CharPtr  labels [] = {
12050   "Molecule", "Technique", "Completedness",
12051   "Class", "Topology", "Strand", NULL
12052 };
12053 
SetupMolInfoBlockPopup(GrouP g,PopuP PNTR p,ValNodePtr PNTR v,EnumFieldAssocPtr al,Boolean IsTo)12054 static void SetupMolInfoBlockPopup (GrouP g, PopuP PNTR p, ValNodePtr PNTR v,
12055                                     EnumFieldAssocPtr al, Boolean IsTo)
12056 {
12057   *p = PopupList (g, TRUE, NULL);
12058   *v = MakeValNodeListFromEnum ( al );
12059   if (IsTo)
12060   {
12061     ReplaceValNodeString (*v, "Any", "No change");
12062   }
12063   InitValNodePopup (*v, *p);
12064   SetValue (*p, 1);
12065 }
12066 
CreateMolInfoBlock(MolInfoBlockPtr mibp,GrouP h,Boolean IsTo)12067 static void CreateMolInfoBlock (MolInfoBlockPtr mibp, GrouP h, Boolean IsTo)
12068 
12069 {
12070   GrouP  g;
12071   Int2   wid;
12072 
12073   if (mibp == NULL || h == NULL) return;
12074   SelectFont (programFont);
12075   wid = MaxStringWidths (labels);
12076   SelectFont (systemFont);
12077 
12078   g = HiddenGroup (h, -2, 0, NULL);
12079 
12080   StaticPrompt (g, "Molecule", wid, popupMenuHeight, programFont, 'l');
12081   SetupMolInfoBlockPopup (g, &(mibp->moltype), &(mibp->moltype_values),
12082                           molinfo_biomol_alist, IsTo);
12083 
12084   StaticPrompt (g, "Technique", wid, popupMenuHeight, programFont, 'l');
12085   SetupMolInfoBlockPopup (g, &(mibp->technique), &(mibp->technique_values),
12086                           molinfo_tech_alist, IsTo);
12087 
12088   StaticPrompt (g, "Completedness", wid, popupMenuHeight, programFont, 'l');
12089   SetupMolInfoBlockPopup (g, &(mibp->complete), &(mibp->complete_values),
12090                           molinfo_complete_alist, IsTo);
12091 
12092   StaticPrompt (g, "Class", wid, popupMenuHeight, programFont, 'l');
12093   SetupMolInfoBlockPopup (g, &(mibp->molPopup), &(mibp->mol_values),
12094                           mol_alist, IsTo);
12095 
12096   StaticPrompt (g, "Topology", wid, popupMenuHeight, programFont, 'l');
12097   SetupMolInfoBlockPopup (g, &(mibp->topologyPopup), &(mibp->topology_values),
12098                           topology_alist, IsTo);
12099 
12100   StaticPrompt (g, "Strand", wid, popupMenuHeight, programFont, 'l');
12101   SetupMolInfoBlockPopup (g, &(mibp->strandPopup), &(mibp->strand_values),
12102                           strand_alist, IsTo);
12103 }
12104 
12105 
12106 typedef struct molinfofrm {
12107   FORM_MESSAGE_BLOCK
12108   DialoG d;
12109   ButtoN leave_dlg_up;
12110 } MolInfoFrmData, PNTR MolInfoFrmPtr;
12111 
DoMolInfoEdit(ButtoN b)12112 static void DoMolInfoEdit (ButtoN b)
12113 {
12114   MolInfoFrmPtr   frm;
12115   SeqEntryPtr sep;
12116   MolinfoBlockPtr mib;
12117 
12118   frm = (MolInfoFrmPtr) GetObjectExtra (b);
12119   if (frm == NULL) {
12120     return;
12121   }
12122 
12123 
12124   sep = GetTopSeqEntryForEntityID (frm->input_entityID);
12125   mib = DialogToPointer (frm->d);
12126   ApplyMolinfoBlockToSeqEntry (sep, mib);
12127   mib = MolinfoBlockFree (mib);
12128 
12129   Update ();
12130   ObjMgrSetDirtyFlag (frm->input_entityID, TRUE);
12131   ObjMgrSendMsg (OM_MSG_UPDATE, frm->input_entityID, 0, 0);
12132   if (!GetStatus (frm->leave_dlg_up)) {
12133     Remove (frm->form);
12134   }
12135 }
12136 
12137 
NewMolInfoFieldsBaseForm(BaseFormPtr bfp,Boolean edit)12138 static void NewMolInfoFieldsBaseForm (BaseFormPtr bfp, Boolean edit)
12139 {
12140   ButtoN          b;
12141   GrouP           c;
12142   GrouP           h;
12143   MolInfoFrmPtr   frm;
12144   WindoW          w;
12145 
12146   if (bfp == NULL) return;
12147   frm = (MolInfoFrmPtr) MemNew (sizeof (MolInfoFrmData));
12148   if (frm == NULL) return;
12149   w = FixedWindow (-50, -33, -10, -10, "Molecule Information Editor", StdCloseWindowProc);
12150   SetObjectExtra (w, frm, StdCleanupFormProc);
12151   frm->form = (ForM) w;
12152   frm->formmessage = NULL;
12153 
12154   frm->input_entityID = bfp->input_entityID;
12155 
12156   h = HiddenGroup (w, -1, 0, NULL);
12157 
12158   frm->d = MolInfoBlockDialog (h, edit, NULL, NULL);
12159   PointerToDialog (frm->d, NULL);
12160 
12161   c = HiddenGroup (w, 3, 0, NULL);
12162   b = DefaultButton (c, "Accept", DoMolInfoEdit);
12163   SetObjectExtra (b, frm, NULL);
12164   PushButton (c, "Cancel", StdCancelButtonProc);
12165   frm->leave_dlg_up = CheckBox (c, "Leave dialog up", NULL);
12166   AlignObjects (ALIGN_CENTER, (HANDLE) frm->d, (HANDLE) c, NULL);
12167   RealizeWindow (w);
12168   Show (w);
12169   Update ();
12170 }
12171 
12172 
NewMolInfoFields(IteM i,Boolean edit)12173 static void NewMolInfoFields (IteM i, Boolean edit)
12174 {
12175   BaseFormPtr     bfp;
12176 
12177 #ifdef WIN_MAC
12178   bfp = currentFormDataPtr;
12179 #else
12180   bfp = GetObjectExtra (i);
12181 #endif
12182   if (bfp == NULL) return;
12183 
12184   NewMolInfoFieldsBaseForm (bfp, edit);
12185 }
12186 
12187 
12188 
NewMolInfoFieldsEdit(IteM i)12189 static void NewMolInfoFieldsEdit (IteM i)
12190 {
12191   NewMolInfoFields (i, TRUE);
12192 }
12193 
12194 
12195 
RibosomalRNAToGenomicDNAVisitFunc(BioseqPtr bsp,Pointer userdata)12196 static void RibosomalRNAToGenomicDNAVisitFunc (
12197   BioseqPtr bsp,
12198   Pointer userdata
12199 )
12200 {
12201   SeqDescrPtr sdp;
12202   MolInfoPtr mip;
12203   SeqMgrDescContext  dcontext;
12204 
12205   if (bsp == NULL) return;
12206 
12207   sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_molinfo, &dcontext);
12208   if (sdp == NULL
12209     || sdp->choice != Seq_descr_molinfo
12210     || sdp->data.ptrvalue == NULL)
12211   {
12212     return;
12213   }
12214   mip = (MolInfoPtr) sdp->data.ptrvalue;
12215   if (mip->biomol == MOLECULE_TYPE_RRNA)
12216   {
12217     mip->biomol = MOLECULE_TYPE_GENOMIC;
12218     bsp->mol = MOLECULE_CLASS_DNA;
12219     bsp->strand = 0;
12220     bsp->topology = 0;
12221   }
12222 }
12223 
RibosomalRNAToGenomicDNA(BaseFormPtr bfp)12224 static void RibosomalRNAToGenomicDNA (BaseFormPtr bfp)
12225 {
12226   SeqEntryPtr     sep;
12227 
12228   if (bfp == NULL) return;
12229   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
12230   if (sep == NULL) return;
12231 
12232   VisitBioseqsInSep (sep, NULL, RibosomalRNAToGenomicDNAVisitFunc);
12233 
12234   Update ();
12235   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
12236   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
12237 }
12238 
12239 
RibosomalRNAToGenomicDNAToolBtn(ButtoN b)12240 static void RibosomalRNAToGenomicDNAToolBtn (ButtoN b)
12241 {
12242   BaseFormPtr  bfp;
12243 
12244   bfp = (BaseFormPtr) GetObjectExtra (b);
12245   if (bfp == NULL) return;
12246 
12247   RibosomalRNAToGenomicDNA (bfp);
12248 }
12249 
MolInfoOkForSeqEntry(SeqEntryPtr sep,SequenceConstraintXPtr scp)12250 static Boolean MolInfoOkForSeqEntry (SeqEntryPtr sep, SequenceConstraintXPtr scp)
12251 {
12252   BioseqSetPtr bssp;
12253   SeqEntryPtr  seq_set;
12254 
12255   if (IS_Bioseq (sep))
12256   {
12257     return DoesSequenceMatchSequenceConstraintX(sep->data.ptrvalue, scp);
12258   }
12259   else if (IS_Bioseq_set (sep))
12260   {
12261     bssp = (BioseqSetPtr) sep->data.ptrvalue;
12262     if (bssp == NULL
12263         || bssp->seq_set == NULL)
12264     {
12265       return FALSE;
12266     }
12267     else if (bssp->_class == BioseqseqSet_class_segset)
12268     {
12269       for (seq_set = bssp->seq_set; seq_set != NULL; seq_set = seq_set->next)
12270       {
12271         if (!MolInfoOkForSeqEntry (seq_set, scp))
12272         {
12273           return FALSE;
12274         }
12275       }
12276       return TRUE;
12277     }
12278     else if (bssp->_class == BioseqseqSet_class_parts)
12279     {
12280       for (seq_set = bssp->seq_set; seq_set != NULL; seq_set = seq_set->next)
12281       {
12282         if (!MolInfoOkForSeqEntry (seq_set, scp))
12283         {
12284           return FALSE;
12285         }
12286       }
12287       return TRUE;
12288     }
12289     else
12290     {
12291       return FALSE;
12292     }
12293   }
12294   else
12295   {
12296     return FALSE;
12297   }
12298 }
12299 
DoApplyMolInfoToBioseq(BioseqPtr bsp,MolInfoEditPtr miep)12300 static void DoApplyMolInfoToBioseq (BioseqPtr bsp, MolInfoEditPtr miep)
12301 {
12302   if (bsp != NULL && miep != NULL)
12303   {
12304     if ( GetValue (miep->to.molPopup) != 1)
12305     {
12306       bsp->mol = (Uint1) GetValNodePopup (miep->to.molPopup,
12307                                           miep->to.mol_values);
12308     }
12309     if ( GetValue (miep->to.strandPopup) != 1)
12310     {
12311       bsp->strand = (Uint1) GetValNodePopup (miep->to.strandPopup,
12312                                              miep->to.strand_values);
12313     }
12314     if (GetValue (miep->to.topologyPopup) != 1)
12315     {
12316       bsp->topology = (Uint1) GetValNodePopup (miep->to.topologyPopup,
12317                                                miep->to.topology_values);
12318     }
12319   }
12320 }
12321 
DoApplyMolInfoToBioseqSet(BioseqSetPtr bssp,MolInfoEditPtr miep)12322 static void DoApplyMolInfoToBioseqSet (BioseqSetPtr bssp, MolInfoEditPtr miep)
12323 {
12324   SeqEntryPtr sep;
12325   if (bssp != NULL && miep != NULL)
12326   {
12327     for (sep = bssp->seq_set; sep != NULL; sep = sep->next)
12328     {
12329       if (IS_Bioseq (sep))
12330       {
12331         DoApplyMolInfoToBioseq (sep->data.ptrvalue, miep);
12332       }
12333       else if (IS_Bioseq_set (sep))
12334       {
12335         DoApplyMolInfoToBioseqSet (sep->data.ptrvalue, miep);
12336       }
12337     }
12338   }
12339 }
12340 
12341 
DoApplyMolInfo(SeqEntryPtr sep,MolInfoEditPtr miep)12342 static void DoApplyMolInfo (SeqEntryPtr sep, MolInfoEditPtr miep)
12343 
12344 {
12345   BioseqPtr     bsp;
12346   BioseqSetPtr  bssp;
12347   MolInfoPtr    mip = NULL;
12348   SeqDescrPtr   sdp;
12349 
12350   if (sep == NULL || sep->data.ptrvalue == NULL || miep == NULL) return;
12351   if (IS_Bioseq_set (sep))
12352   {
12353     bssp = (BioseqSetPtr) sep->data.ptrvalue;
12354 /* this also delves into nuc-prot sets */
12355     if (bssp != NULL && (bssp->_class == 7 ||
12356                          (IsPopPhyEtcSet (bssp->_class)) ||
12357                          bssp->_class == 1)) {
12358       for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
12359         DoApplyMolInfo (sep, miep);
12360       }
12361       return;
12362     }
12363   }
12364   else if (!MolInfoOkForSeqEntry(sep, miep->scp))
12365   {
12366     return;
12367   }
12368 
12369   bsp = NULL;
12370   bssp = NULL;
12371   sdp = SeqEntryGetSeqDescr (sep, Seq_descr_molinfo, NULL);
12372   if (!miep->allow_existing && sdp != NULL) return;
12373 
12374   if (IS_Bioseq (sep)) {
12375     bsp = (BioseqPtr) sep->data.ptrvalue;
12376     if (DoesSequenceMatchSequenceConstraintX(bsp, miep->scp)) {
12377       DoApplyMolInfoToBioseq (bsp, miep);
12378     } else return;
12379   } else if (IS_Bioseq_set (sep)) {
12380     bssp = (BioseqSetPtr) sep->data.ptrvalue;
12381     DoApplyMolInfoToBioseqSet (bssp, miep);
12382   } else return;
12383   if (sdp != NULL)
12384   {
12385     mip = (MolInfoPtr) sdp->data.ptrvalue;
12386   }
12387   if (mip == NULL)
12388   {
12389     mip = MolInfoNew ();
12390   }
12391   if (mip == NULL) return;
12392   if (sdp == NULL)
12393   {
12394     sdp = CreateNewDescriptor (sep, Seq_descr_molinfo);
12395   }
12396   if (sdp == NULL) return;
12397   sdp->data.ptrvalue = mip;
12398 
12399   if ( GetValue (miep->to.moltype) != 1)
12400   {
12401     mip->biomol = (Uint1) GetValNodePopup (miep->to.moltype,
12402                                            miep->to.moltype_values);
12403   }
12404   if ( GetValue (miep->to.technique) != 1)
12405   {
12406     mip->tech = (Uint1) GetValNodePopup (miep->to.technique,
12407                                          miep->to.technique_values);
12408   }
12409   if ( GetValue (miep->to.complete) != 1)
12410   {
12411     mip->completeness = (Uint1) GetValNodePopup (miep->to.complete,
12412                                                  miep->to.complete_values);
12413   }
12414 }
12415 
WillEditMolInfo(MolInfoEditPtr miep)12416 static Boolean WillEditMolInfo (MolInfoEditPtr miep)
12417 {
12418   if (miep == NULL)
12419   {
12420     return FALSE;
12421   }
12422   else if (GetValue (miep->to.moltype) != 1
12423            || GetValue (miep->to.technique) != 1
12424            || GetValue (miep->to.complete) != 1)
12425   {
12426     return TRUE;
12427   }
12428   else
12429   {
12430     return FALSE;
12431   }
12432 }
12433 
12434 typedef struct molinfocheck {
12435   SequenceConstraintXPtr scp;
12436   Int4                  num_with;
12437   Int4                  num_without;
12438 } MolInfoCheckData, PNTR MolInfoCheckPtr;
12439 
CheckForExistingMolInfo(SeqEntryPtr sep,MolInfoCheckPtr micp)12440 static void CheckForExistingMolInfo (SeqEntryPtr sep, MolInfoCheckPtr micp)
12441 
12442 {
12443   BioseqPtr     bsp;
12444   BioseqSetPtr  bssp;
12445   SeqDescrPtr   sdp;
12446 
12447   if (sep == NULL || sep->data.ptrvalue == NULL || micp == NULL) return;
12448   if (IS_Bioseq_set (sep)) {
12449     bssp = (BioseqSetPtr) sep->data.ptrvalue;
12450 /* this also delves into nuc-prot sets */
12451     if (bssp != NULL && (bssp->_class == 7 ||
12452                          (IsPopPhyEtcSet (bssp->_class)) ||
12453                          bssp->_class == 1)) {
12454       for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
12455         CheckForExistingMolInfo (sep, micp);
12456       }
12457       return;
12458     }
12459   }
12460   bsp = NULL;
12461   bssp = NULL;
12462   sdp = SeqEntryGetSeqDescr (sep, Seq_descr_molinfo, NULL);
12463   if (MolInfoOkForSeqEntry (sep, micp->scp))
12464   {
12465     if (sdp == NULL)
12466     {
12467       micp->num_without++;
12468     }
12469     else
12470     {
12471       micp->num_with++;
12472     }
12473   }
12474 }
12475 
12476 
DoProcessApplyMolInfo(ButtoN b)12477 static void DoProcessApplyMolInfo (ButtoN b)
12478 
12479 {
12480   MolInfoEditPtr   miep;
12481   MolInfoCheckData micd;
12482   Int4             opt;
12483   Char             err_msg[1000];
12484   CharPtr          err_fmt = "%d sequences that match your constraint already have MolInfo descriptors.";
12485 
12486   miep = (MolInfoEditPtr) GetObjectExtra (b);
12487   if (miep == NULL) return;
12488   Hide (miep->form);
12489   WatchCursor ();
12490   Update ();
12491   miep->scp = DialogToPointer (miep->sequence_constraint);
12492   micd.scp = miep->scp;
12493   micd.num_with = 0;
12494   micd.num_without = 0;
12495 
12496   CheckForExistingMolInfo (miep->sep, &micd);
12497   if (micd.num_with == 0 && micd.num_without == 0)
12498   {
12499     Message (MSG_ERROR, "No sequences meet your constraint!");
12500     return;
12501   }
12502 
12503   if (WillEditMolInfo (miep))
12504   {
12505     miep->allow_existing = FALSE;
12506     if (micd.num_without == 0)
12507     {
12508       opt = ThreeOptionsDlg ("MolInfo Descriptors Already Exist",
12509                              "All sequences that match your constraint already have MolInfo descriptors.",
12510                              "Edit existing MolInfo descriptors",
12511                              "Cancel",
12512                              NULL);
12513       if (opt == 2)
12514       {
12515         return;
12516       }
12517       else
12518       {
12519         miep->allow_existing = TRUE;
12520       }
12521     }
12522     else
12523     {
12524       sprintf (err_msg, err_fmt, micd.num_with);
12525       opt = ThreeOptionsDlg ("MolInfo Descriptors Already Exist", err_msg,
12526                              "Continue and edit existing MolInfo descriptors",
12527                              "Continue, but skip existing MolInfo descriptors",
12528                              "Cancel");
12529       if (opt == 3)
12530       {
12531         return;
12532       }
12533       else if (opt == 1)
12534       {
12535         miep->allow_existing = TRUE;
12536       }
12537     }
12538   }
12539   else
12540   {
12541     miep->allow_existing = TRUE;
12542   }
12543 
12544   DoApplyMolInfo (miep->sep, miep);
12545   FreeMolInfoBlockData (&miep->to);
12546   miep->scp = SequenceConstraintXFree (miep->scp);
12547   ArrowCursor ();
12548   Update ();
12549   ObjMgrSetDirtyFlag (miep->input_entityID, TRUE);
12550   ObjMgrSendMsg (OM_MSG_UPDATE, miep->input_entityID, 0, 0);
12551   Remove (miep->form);
12552 }
12553 
ApplyMolInfo(IteM i)12554 static void ApplyMolInfo (IteM i)
12555 
12556 {
12557   ButtoN          b;
12558   BaseFormPtr     bfp;
12559   GrouP           c;
12560   GrouP           g;
12561   GrouP           h;
12562   MolInfoEditPtr  miep;
12563   SeqEntryPtr     sep;
12564   WindoW          w;
12565 
12566 #ifdef WIN_MAC
12567   bfp = currentFormDataPtr;
12568 #else
12569   bfp = GetObjectExtra (i);
12570 #endif
12571   if (bfp == NULL) return;
12572   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
12573   if (sep == NULL) return;
12574   miep = (MolInfoEditPtr) MemNew (sizeof (MolInfoEdit));
12575   if (miep == NULL) return;
12576   w = FixedWindow (-50, -33, -10, -10, "Apply Molecule Information", StdCloseWindowProc);
12577   SetObjectExtra (w, miep, StdCleanupFormProc);
12578   miep->form = (ForM) w;
12579   miep->formmessage = NULL;
12580 
12581   miep->sep = sep;
12582   miep->input_entityID = bfp->input_entityID;
12583 
12584   g = HiddenGroup (w, 2, 0, NULL);
12585   h = HiddenGroup (g, 0, 2, NULL);
12586   CreateMolInfoBlock (&miep->to, h, TRUE);
12587 
12588   miep->sequence_constraint = SequenceConstraintXDialog (w);
12589 
12590   c = HiddenGroup (w, 2, 0, NULL);
12591   b = DefaultButton (c, "Accept", DoProcessApplyMolInfo);
12592   SetObjectExtra (b, miep, NULL);
12593   PushButton (c, "Cancel", StdCancelButtonProc);
12594   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) miep->sequence_constraint, (HANDLE) c, NULL);
12595   RealizeWindow (w);
12596   Show (w);
12597   Update ();
12598 }
12599 
12600 typedef struct objstringdata
12601 {
12602   CharPtr match;
12603   Boolean found;
12604   Boolean insensitive;
12605   Boolean whole_word;
12606 } ObjStringData, PNTR ObjStringPtr;
12607 
12608 
StringMatchesConstraint(CharPtr pchSource,ObjStringPtr osp)12609 static Boolean StringMatchesConstraint (CharPtr pchSource, ObjStringPtr osp)
12610 {
12611   CharPtr pchFind;
12612   CharPtr pFound;
12613 
12614   if (pchSource == NULL || osp == NULL) return FALSE;
12615 
12616 	pchFind = osp->match;
12617 
12618 	if (osp->insensitive)
12619 	{
12620 	  pFound = StringISearch (pchSource, pchFind);
12621 	}
12622 	else
12623 	{
12624 	  pFound = StringSearch (pchSource, pchFind);
12625 	}
12626 
12627 	if (pFound != NULL)
12628 	{
12629 	  if (!osp->whole_word)
12630 	  {
12631 	    return TRUE;
12632 	  }
12633 	  else if ((pFound == pchSource || (! isalpha ((Int4)(*(pFound - 1))) && ! isdigit ((Int4)(*(pFound - 1)))))
12634 	           && ! isalpha ((Int4)(*(pFound + StringLen (pchFind))))
12635 	           && ! isdigit ((Int4)(*(pFound + StringLen (pchFind)))))
12636 	  {
12637 	    return TRUE;
12638 	  }
12639 	}
12640 	return FALSE;
12641 }
12642 
AsnWriteSearchCallBack(AsnExpOptStructPtr pAEOS)12643 static void LIBCALLBACK AsnWriteSearchCallBack (AsnExpOptStructPtr pAEOS)
12644 
12645 {
12646   CharPtr        pchSource;
12647   ObjStringPtr   osp;
12648 
12649   osp = (ObjStringPtr) pAEOS->data;
12650   if (ISA_STRINGTYPE (AsnFindBaseIsa (pAEOS->atp)))
12651   {
12652 	  pchSource = (CharPtr) pAEOS->dvp->ptrvalue;
12653 	  osp->found |= StringMatchesConstraint (pchSource, osp);
12654   }
12655 }
12656 
12657 
ObjectHasSubstring(ObjMgrTypePtr omtp,AsnIoPtr aip,Pointer ptr,ObjStringPtr osp)12658 static Boolean ObjectHasSubstring (ObjMgrTypePtr omtp, AsnIoPtr aip, Pointer ptr, ObjStringPtr osp)
12659 
12660 {
12661   osp->found = FALSE;
12662   (omtp->asnwrite) (ptr, aip, NULL);
12663   return osp->found;
12664 }
12665 
OperateOnBioseqFeaturesWithText(BioseqPtr bsp,Pointer userdata)12666 extern void OperateOnBioseqFeaturesWithText
12667 (BioseqPtr         bsp,
12668  Pointer           userdata)
12669 {
12670   AsnExpOptPtr            aeop;
12671   AsnIoPtr                aip;
12672   ObjStringData           osd;
12673   SeqFeatPtr              sfp;
12674   ObjMgrPtr               omp;
12675   ObjMgrTypePtr           omtp;
12676   SeqMgrFeatContext       fcontext;
12677   FeaturesWithTextPtr     fdp;
12678 
12679   fdp = (FeaturesWithTextPtr) userdata;
12680   if (bsp == NULL || fdp == NULL || fdp->callback == NULL || fdp->search_text == NULL) return;
12681   omp = ObjMgrGet ();
12682   if (omp == NULL) return;
12683   omtp = ObjMgrTypeFind (omp, OBJ_SEQFEAT, NULL, NULL);
12684   if (omtp == NULL) return;
12685 
12686   aip = AsnIoNullOpen ();
12687   osd.insensitive = fdp->case_insensitive;
12688   osd.whole_word = fdp->whole_word;
12689 
12690   aeop = AsnExpOptNew (aip, NULL, NULL, AsnWriteSearchCallBack);
12691   if (aeop != NULL) {
12692     aeop->user_data = (Pointer) &osd;
12693   }
12694   osd.match = fdp->search_text;
12695 
12696   sfp = NULL;
12697   while ((sfp = SeqMgrGetNextFeature (bsp, sfp, fdp->seqFeatChoice, fdp->featDefChoice, &fcontext)) != NULL)
12698   {
12699     if (fdp->no_text || ObjectHasSubstring (omtp, aip, (Pointer) sfp, &osd))
12700     {
12701       fdp->callback (sfp, fdp->userdata);
12702     }
12703     else if (StringMatchesConstraint(fcontext.label, &osd))
12704     {
12705       fdp->callback (sfp, fdp->userdata);
12706     }
12707   }
12708   AsnIoClose (aip);
12709 }
12710 
12711 typedef struct seqentryitemswithtext
12712 {
12713   FeaturesWithTextPtr    fdp;
12714   DescriptorsWithTextPtr ddp;
12715   ObjMgrTypePtr          omtp;
12716   AsnIoPtr               aip;
12717   Uint2                  entityID;
12718   ObjStringData          osd;
12719 } SeqEntryItemsWithTextData, PNTR SeqEntryItemsWithTextPtr;
12720 
SeqEntryFeaturesWithTextCallback(SeqFeatPtr sfp,Pointer userdata)12721 static void SeqEntryFeaturesWithTextCallback (SeqFeatPtr sfp, Pointer userdata)
12722 {
12723   SeqMgrFeatContext fcontext;
12724   SeqEntryItemsWithTextPtr sp;
12725 
12726   if (sfp == NULL || userdata == NULL) return;
12727   sp = (SeqEntryItemsWithTextPtr) userdata;
12728   sfp = SeqMgrGetDesiredFeature (sp->entityID, NULL, 0, 0, sfp, &fcontext);
12729   if (sfp == NULL) return;
12730 
12731   if (sp->fdp->seqFeatChoice != 0 && sp->fdp->seqFeatChoice != sfp->data.choice) return;
12732   if (sp->fdp->featDefChoice != 0 && sp->fdp->featDefChoice != sfp->idx.subtype) return;
12733 
12734   if (sp->fdp->no_text
12735       || (! sp->fdp->act_when_string_not_present &&
12736          (ObjectHasSubstring (sp->omtp, sp->aip, (Pointer) sfp, &(sp->osd))
12737           || StringMatchesConstraint (fcontext.label, &(sp->osd))))
12738       || (sp->fdp->act_when_string_not_present
12739           && ! ObjectHasSubstring (sp->omtp, sp->aip, (Pointer) sfp, &(sp->osd))
12740           && ! StringMatchesConstraint (fcontext.label, &(sp->osd))))
12741   {
12742     sp->fdp->callback (sfp, sp->fdp->userdata);
12743   }
12744 }
12745 
OperateOnSeqEntryFeaturesWithText(SeqEntryPtr sep,FeaturesWithTextPtr fdp)12746 extern void OperateOnSeqEntryFeaturesWithText (SeqEntryPtr sep, FeaturesWithTextPtr fdp)
12747 {
12748   SeqEntryItemsWithTextData sd;
12749   ObjMgrPtr                 omp;
12750   AsnExpOptPtr              aeop;
12751 
12752   if (sep == NULL || fdp == NULL) return;
12753 
12754   sd.fdp = fdp;
12755   sd.entityID = SeqMgrGetEntityIDForSeqEntry (sep);
12756   omp = ObjMgrGet ();
12757   if (omp == NULL) return;
12758   sd.omtp = ObjMgrTypeFind (omp, OBJ_SEQFEAT, NULL, NULL);
12759   if (sd.omtp == NULL) return;
12760 
12761   sd.aip = AsnIoNullOpen ();
12762   sd.osd.insensitive = fdp->case_insensitive;
12763   sd.osd.whole_word = fdp->whole_word;
12764   aeop = AsnExpOptNew (sd.aip, NULL, NULL, AsnWriteSearchCallBack);
12765   if (aeop != NULL) {
12766     aeop->user_data = (Pointer) &(sd.osd);
12767   }
12768   sd.osd.match = fdp->search_text;
12769 
12770   VisitFeaturesInSep (sep, &sd, SeqEntryFeaturesWithTextCallback);
12771   AsnIoClose (sd.aip);
12772 }
12773 
12774 
SeqEntryDescriptorsWithTextCallback(SeqDescrPtr sdp,Pointer userdata)12775 static void SeqEntryDescriptorsWithTextCallback (SeqDescrPtr sdp, Pointer userdata)
12776 {
12777   SeqEntryItemsWithTextPtr sp;
12778 
12779   if (sdp == NULL || userdata == NULL) return;
12780   sp = (SeqEntryItemsWithTextPtr) userdata;
12781   if (sp->ddp->no_text
12782       || (! sp->ddp->act_when_string_not_present && ObjectHasSubstring (sp->omtp, sp->aip, (Pointer) sdp, &(sp->osd)))
12783       || (sp->ddp->act_when_string_not_present && ! ObjectHasSubstring (sp->omtp, sp->aip, (Pointer) sdp, &(sp->osd))))
12784   {
12785     sp->ddp->callback (sdp, sp->ddp->userdata);
12786   }
12787 }
12788 
12789 
OperateOnSeqEntryDescriptorsWithText(SeqEntryPtr sep,DescriptorsWithTextPtr ddp)12790 extern void OperateOnSeqEntryDescriptorsWithText (SeqEntryPtr sep, DescriptorsWithTextPtr ddp)
12791 {
12792   SeqEntryItemsWithTextData sd;
12793   ObjMgrPtr                 omp;
12794   AsnExpOptPtr              aeop;
12795 
12796   if (sep == NULL || ddp == NULL) return;
12797 
12798   sd.ddp = ddp;
12799   sd.entityID = SeqMgrGetEntityIDForSeqEntry (sep);
12800   omp = ObjMgrGet ();
12801   if (omp == NULL) return;
12802   sd.omtp = ObjMgrTypeFind (omp, OBJ_SEQDESC, NULL, NULL);
12803   if (sd.omtp == NULL) return;
12804 
12805   sd.aip = AsnIoNullOpen ();
12806   sd.osd.insensitive = ddp->case_insensitive;
12807   sd.osd.whole_word = ddp->whole_word;
12808   aeop = AsnExpOptNew (sd.aip, NULL, NULL, AsnWriteSearchCallBack);
12809   if (aeop != NULL) {
12810     aeop->user_data = (Pointer) &(sd.osd);
12811   }
12812   sd.osd.match = ddp->search_text;
12813 
12814   VisitDescriptorsInSep (sep, &sd, SeqEntryDescriptorsWithTextCallback);
12815   AsnIoClose (sd.aip);
12816 }
12817 
12818 
GenePseudoOn(SeqFeatPtr sfp,Pointer userdata)12819 static void GenePseudoOn (SeqFeatPtr sfp, Pointer userdata)
12820 
12821 {
12822   GeneRefPtr  grp;
12823   ValNode     field;
12824 
12825   if (sfp->data.choice != SEQFEAT_GENE) return;
12826   grp = (GeneRefPtr) sfp->data.value.ptrvalue;
12827   if (grp == NULL) return;
12828   grp->pseudo = TRUE;
12829   if (userdata != NULL && StringCmp((CharPtr)userdata, "Unqualified") != 0) {
12830     MemSet (&field, 0, sizeof (ValNode));
12831     field.choice = FeatQualChoice_legal_qual;
12832     field.data.intvalue = Feat_qual_legal_pseudo;
12833     SetStringInGBQualList (&(sfp->qual), &field, NULL, (CharPtr)userdata, ExistingTextOption_replace_old);
12834   }
12835 
12836 }
12837 
GenePseudoOff(SeqFeatPtr sfp,Pointer userdata)12838 static void GenePseudoOff (SeqFeatPtr sfp, Pointer userdata)
12839 
12840 {
12841   GeneRefPtr  grp;
12842 
12843   if (sfp->data.choice != SEQFEAT_GENE) return;
12844   grp = (GeneRefPtr) sfp->data.value.ptrvalue;
12845   if (grp == NULL) return;
12846   grp->pseudo = FALSE;
12847   sfp->pseudo = FALSE;
12848   RemoveGBQualMatch (&(sfp->qual), "pseudogene", 0, NULL);
12849 }
12850 
12851 typedef struct genepseudodata
12852 {
12853   FORM_MESSAGE_BLOCK
12854   Boolean set_on;
12855   TexT    search_text;
12856   ButtoN  case_insensitive;
12857   ButtoN  when_string_not_present;
12858   PopuP   pseudo_val;
12859 } GenePseudoData, PNTR GenePseudoPtr;
12860 
DoGenePseudoConstraint(ButtoN b)12861 static void DoGenePseudoConstraint (ButtoN b)
12862 {
12863   GenePseudoPtr        gsp;
12864   Char                 search_text[255];
12865   FeaturesWithTextData fd;
12866   SeqEntryPtr          sep;
12867 
12868   gsp = (GenePseudoPtr) GetObjectExtra (b);
12869   if (gsp == NULL) return;
12870 
12871   sep = GetTopSeqEntryForEntityID (gsp->input_entityID);
12872   if (sep == NULL) return;
12873 
12874   GetTitle (gsp->search_text, search_text, sizeof (search_text) - 1);
12875 
12876   /* set up text operation */
12877   fd.seqFeatChoice = SEQFEAT_GENE;
12878   fd.featDefChoice = 0;
12879   fd.search_text = search_text;
12880   fd.no_text = StringHasNoText (search_text);
12881   fd.case_insensitive = GetStatus (gsp->case_insensitive);
12882   fd.whole_word = FALSE;
12883   fd.act_when_string_not_present = GetStatus (gsp->when_string_not_present);
12884   fd.userdata = NULL;
12885   if (gsp->set_on)
12886   {
12887     fd.callback = GenePseudoOn;
12888     fd.userdata = GetEnumPopupByName (gsp->pseudo_val, legacy_pseudogene_alist + 1);
12889   }
12890   else
12891   {
12892   	fd.callback = GenePseudoOff;
12893   }
12894 
12895   OperateOnSeqEntryFeaturesWithText (sep, &fd);
12896   ObjMgrSetDirtyFlag (gsp->input_entityID, TRUE);
12897   ObjMgrSendMsg (OM_MSG_UPDATE, gsp->input_entityID, 0, 0);
12898   Update ();
12899   Remove (gsp->form);
12900 }
12901 
GenePseudoConstraint(IteM i,Boolean set_on)12902 static void GenePseudoConstraint (IteM i, Boolean set_on)
12903 {
12904   BaseFormPtr        bfp;
12905   WindoW             w;
12906   GenePseudoPtr      gsp;
12907   GrouP              h, g, c;
12908   ButtoN             b;
12909 
12910 #ifdef WIN_MAC
12911   bfp = currentFormDataPtr;
12912 #else
12913   bfp = GetObjectExtra (i);
12914 #endif
12915   if (bfp == NULL) return;
12916 
12917   gsp = (GenePseudoPtr) MemNew (sizeof (GenePseudoData));
12918   if (gsp == NULL) return;
12919 
12920   gsp->input_entityID = bfp->input_entityID;
12921   gsp->set_on = set_on;
12922   if (gsp->set_on)
12923   {
12924     w = FixedWindow (-50, -33, -10, -10, "Set Gene Pseudo", StdCloseWindowProc);
12925   }
12926   else
12927   {
12928     w = FixedWindow (-50, -33, -10, -10, "Clear Gene Pseudo", StdCloseWindowProc);
12929   }
12930   SetObjectExtra (w, gsp, StdCleanupFormProc);
12931   gsp->form = (ForM) w;
12932 
12933   h = HiddenGroup (w, -1, 0, NULL);
12934   SetGroupSpacing (h, 10, 10);
12935 
12936   if (gsp->set_on) {
12937     gsp->pseudo_val = PopupList (h, TRUE, NULL);
12938     InitEnumPopup (gsp->pseudo_val, legacy_pseudogene_alist + 1, NULL);
12939   }
12940 
12941   g = HiddenGroup (h, 0, 4, NULL);
12942   StaticPrompt (g, "String Constraint", 0, 0, programFont, 'c');
12943   gsp->search_text = DialogText (g, "", 20, NULL);
12944   gsp->case_insensitive = CheckBox (g, "Case Insensitive", NULL);
12945   gsp->when_string_not_present = CheckBox (g, "When String Not Present", NULL);
12946 
12947   c = HiddenGroup (h, 4, 0, NULL);
12948   b = DefaultButton (c, "Accept", DoGenePseudoConstraint);
12949   SetObjectExtra (b, gsp, NULL);
12950   PushButton (c, "Cancel", StdCancelButtonProc);
12951 
12952   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, (HANDLE) gsp->pseudo_val, NULL);
12953 
12954   RealizeWindow (w);
12955   Show (w);
12956   Select (gsp->search_text);
12957   Update ();
12958 }
12959 
AddGenePseudo(IteM i)12960 static void AddGenePseudo (IteM i)
12961 
12962 {
12963   GenePseudoConstraint (i, TRUE);
12964 }
12965 
ClearOrfCallback(GatherContextPtr gcp)12966 static Boolean ClearOrfCallback (GatherContextPtr gcp)
12967 
12968 {
12969   CdRegionPtr  crp;
12970   SeqFeatPtr   sfp;
12971 
12972   if (gcp == NULL) return TRUE;
12973   if (gcp->thistype != OBJ_SEQFEAT) return TRUE;
12974   sfp = (SeqFeatPtr) gcp->thisitem;
12975   if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) return TRUE;
12976   crp = (CdRegionPtr) sfp->data.value.ptrvalue;
12977   if (crp == NULL) return TRUE;
12978   crp->orf = FALSE;
12979   return TRUE;
12980 }
12981 
ClearOrfFlagInCDS(IteM i)12982 static void ClearOrfFlagInCDS (IteM i)
12983 
12984 {
12985   BaseFormPtr  bfp;
12986   GatherScope  gs;
12987   SeqEntryPtr  sep;
12988 
12989 #ifdef WIN_MAC
12990   bfp = currentFormDataPtr;
12991 #else
12992   bfp = GetObjectExtra (i);
12993 #endif
12994   if (bfp == NULL) return;
12995   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
12996   if (sep == NULL) return;
12997   MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
12998   gs.seglevels = 1;
12999   gs.get_feats_location = FALSE;
13000   MemSet((Pointer)(gs.ignore), (int)(TRUE), (size_t)(OBJ_MAX * sizeof(Boolean)));
13001   gs.ignore[OBJ_BIOSEQ] = FALSE;
13002   gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
13003   gs.ignore[OBJ_SEQFEAT] = FALSE;
13004   gs.ignore[OBJ_SEQANNOT] = FALSE;
13005   GatherEntity (bfp->input_entityID, NULL, ClearOrfCallback, &gs);
13006   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
13007   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
13008 }
13009 
13010 
ConvertTranslExceptCallback(GatherContextPtr gcp)13011 static Boolean ConvertTranslExceptCallback (GatherContextPtr gcp)
13012 
13013 {
13014   CdRegionPtr  crp;
13015   SeqFeatPtr   sfp;
13016   CharPtr      text = "RNA editing";
13017 
13018   if (gcp == NULL) return TRUE;
13019   if (gcp->thistype != OBJ_SEQFEAT) return TRUE;
13020   sfp = (SeqFeatPtr) gcp->thisitem;
13021   if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) return TRUE;
13022   crp = (CdRegionPtr) sfp->data.value.ptrvalue;
13023   if (crp == NULL || crp->code_break == NULL) return TRUE;
13024   crp->code_break = CodeBreakFree (crp->code_break);
13025   sfp->excpt = TRUE;
13026   if (sfp->except_text != NULL)
13027   {
13028   	MemFree (sfp->except_text);
13029   }
13030   sfp->except_text = (CharPtr) MemNew (sizeof (Char) * (StringLen (text) + 1));
13031   if (sfp->except_text != NULL)
13032   {
13033   	StringCpy (sfp->except_text, text);
13034   }
13035   return TRUE;
13036 }
13037 
ConvertTranslExceptToRNAEditingException(IteM i)13038 static void ConvertTranslExceptToRNAEditingException (IteM i)
13039 
13040 {
13041   BaseFormPtr  bfp;
13042   GatherScope  gs;
13043   SeqEntryPtr  sep;
13044 
13045 #ifdef WIN_MAC
13046   bfp = currentFormDataPtr;
13047 #else
13048   bfp = GetObjectExtra (i);
13049 #endif
13050   if (bfp == NULL) return;
13051   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
13052   if (sep == NULL) return;
13053   MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
13054   gs.seglevels = 1;
13055   gs.get_feats_location = FALSE;
13056   MemSet((Pointer)(gs.ignore), (int)(TRUE), (size_t)(OBJ_MAX * sizeof(Boolean)));
13057   gs.ignore[OBJ_BIOSEQ] = FALSE;
13058   gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
13059   gs.ignore[OBJ_SEQFEAT] = FALSE;
13060   gs.ignore[OBJ_SEQANNOT] = FALSE;
13061   GatherEntity (bfp->input_entityID, NULL, ConvertTranslExceptCallback, &gs);
13062   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
13063   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
13064 }
13065 
13066 typedef struct bioseqsetform {
13067   FEATURE_FORM_BLOCK
13068   BioseqSetPtr       bssp;
13069   Uint2              entityID;
13070   PopuP              class_control;
13071 } BioseqSetForm, PNTR BioseqSetFormPtr;
13072 
ENUM_ALIST(bioseqset_class_alist)13073 static ENUM_ALIST(bioseqset_class_alist)
13074   {"  ",                     0},
13075   {"Nuc-prot",               1},
13076   {"Segset",                 2},
13077   {"Conset",                 3},
13078   {"Parts",                  4},
13079   {"Gibb",                   5},
13080   {"GI",                     6},
13081   {"PIR",                    8},
13082   {"Genbank",                7},
13083   {"Pubset",                 9},
13084   {"Equiv",                 10},
13085   {"Swissprot",             11},
13086   {"PDB-entry",             12},
13087   {"Mut-set",               13},
13088   {"Pop-set",               14},
13089   {"Phy-set",               15},
13090   {"Eco-set",               16},
13091   {"Gen-prod-set",          17},
13092   {"WGS-set",               18},
13093   {"Small-genome-set",      23},
13094   {"Other",                255},
13095 END_ENUM_ALIST
13096 
13097 static void AcceptBioseqSetEditProc (ButtoN b)
13098 
13099 {
13100   BioseqSetFormPtr  bsfp;
13101   BioseqSetPtr      bssp;
13102   UIEnum            val;
13103 
13104   bsfp = (BioseqSetFormPtr) GetObjectExtra (b);
13105   if (bsfp != NULL) {
13106     Hide (bsfp->form);
13107     bssp = bsfp->bssp;
13108     if (bssp == NULL && bsfp->entityID == 0) {
13109       bssp = BioseqSetNew ();
13110     }
13111     if (bssp != NULL) {
13112       GetEnumPopup (bsfp->class_control, bioseqset_class_alist, &val);
13113       bssp->_class = (Uint1) val;
13114       if (bsfp->entityID == 0) {
13115         if (! ObjMgrRegister (OBJ_BIOSEQSET, (Pointer) bssp)) {
13116           Message (MSG_ERROR, "ObjMgrRegister failed");
13117         }
13118       }
13119     }
13120     Remove (bsfp->form);
13121     ObjMgrSetDirtyFlag (bsfp->entityID, TRUE);
13122     ObjMgrSendMsg (OM_MSG_UPDATE, bsfp->entityID, 0, 0);
13123   }
13124 }
13125 
CreateBioseqSetMessageProc(ForM f,Int2 mssg)13126 static void CreateBioseqSetMessageProc (ForM f, Int2 mssg)
13127 
13128 {
13129   StdEditorProcsPtr  sepp;
13130 
13131   sepp = (StdEditorProcsPtr) GetAppProperty ("StdEditorForm");
13132   if (sepp != NULL) {
13133     if (sepp->handleMessages != NULL) {
13134       sepp->handleMessages (f, mssg);
13135     }
13136   }
13137 }
13138 
CreateBioseqSetEditForm(BioseqSetPtr bssp,Uint2 entityID)13139 static ForM CreateBioseqSetEditForm (BioseqSetPtr bssp, Uint2 entityID)
13140 
13141 {
13142   ButtoN            b;
13143   BioseqSetFormPtr  bsfp;
13144   GrouP             c;
13145   GrouP             h;
13146   WindoW            w = NULL;
13147 
13148   bsfp = (BioseqSetFormPtr) MemNew (sizeof (BioseqSetForm));
13149   if (bsfp != NULL) {
13150     w = FixedWindow (-50, -33, -10, -10, "Bioseq Set", NULL);
13151     SetObjectExtra (w, bsfp, StdCleanupFormProc);
13152     bsfp->form = (ForM) w;
13153     bsfp->formmessage = CreateBioseqSetMessageProc;
13154 
13155     bsfp->bssp = bssp;
13156     bsfp->entityID = entityID;
13157 
13158     h = HiddenGroup (w, -2, 0, NULL);
13159     StaticPrompt (h, "Class", 0, popupMenuHeight, programFont, 'l');
13160     bsfp->class_control = PopupList (h, TRUE, NULL);
13161     SetObjectExtra (bsfp->class_control, bsfp, NULL);
13162     InitEnumPopup (bsfp->class_control, bioseqset_class_alist, NULL);
13163     if (bssp != NULL) {
13164       SetEnumPopup (bsfp->class_control, bioseqset_class_alist, (UIEnum) bssp->_class);
13165     }
13166 
13167     c = HiddenGroup (w, 2, 0, NULL);
13168     b = DefaultButton (c, "Accept", AcceptBioseqSetEditProc);
13169     SetObjectExtra (b, bsfp, NULL);
13170     PushButton (c, "Cancel", StdCancelButtonProc);
13171     AlignObjects (ALIGN_CENTER, (HANDLE) h, (HANDLE) c, NULL);
13172     RealizeWindow (w);
13173   }
13174   return (ForM) w;
13175 }
13176 
13177 
DoApplySetType(ButtoN b)13178 static void DoApplySetType (ButtoN b)
13179 {
13180   BioseqSetFormPtr  bsfp;
13181   BioseqSetPtr      bssp;
13182   UIEnum            val;
13183   SeqEntryPtr       sep;
13184 
13185   bsfp = (BioseqSetFormPtr) GetObjectExtra (b);
13186   if (bsfp != NULL) {
13187     Hide (bsfp->form);
13188     bssp = bsfp->bssp;
13189     if (bssp == NULL && bsfp->entityID == 0) {
13190       bssp = BioseqSetNew ();
13191     }
13192     if (bssp != NULL) {
13193       GetEnumPopup (bsfp->class_control, bioseqset_class_alist, &val);
13194       sep = SeqMgrGetSeqEntryForData (bssp);
13195       ApplySetTypeToSeqEntry (sep, val, TRUE);
13196 
13197     }
13198     Remove (bsfp->form);
13199     ObjMgrSetDirtyFlag (bsfp->entityID, TRUE);
13200     ObjMgrSendMsg (OM_MSG_UPDATE, bsfp->entityID, 0, 0);
13201   }
13202 }
13203 
13204 
ApplySetTypeToInnerSets(BioseqSetPtr bssp,Uint2 entityID)13205 NLM_EXTERN void ApplySetTypeToInnerSets (BioseqSetPtr bssp, Uint2 entityID)
13206 {
13207   ButtoN            b;
13208   BioseqSetFormPtr  bsfp;
13209   GrouP             c;
13210   GrouP             h;
13211   WindoW            w = NULL;
13212 
13213   bsfp = (BioseqSetFormPtr) MemNew (sizeof (BioseqSetForm));
13214   if (bsfp != NULL) {
13215     w = FixedWindow (-50, -33, -10, -10, "Convert Set Type", NULL);
13216     SetObjectExtra (w, bsfp, StdCleanupFormProc);
13217     bsfp->form = (ForM) w;
13218     bsfp->formmessage = CreateBioseqSetMessageProc;
13219 
13220     bsfp->bssp = bssp;
13221     bsfp->entityID = entityID;
13222 
13223     h = HiddenGroup (w, -2, 0, NULL);
13224     StaticPrompt (h, "Class", 0, popupMenuHeight, programFont, 'l');
13225     bsfp->class_control = PopupList (h, TRUE, NULL);
13226     SetObjectExtra (bsfp->class_control, bsfp, NULL);
13227     InitEnumPopup (bsfp->class_control, bioseqset_class_alist, NULL);
13228     if (bssp != NULL) {
13229       SetEnumPopup (bsfp->class_control, bioseqset_class_alist, (UIEnum) bssp->_class);
13230     }
13231 
13232     c = HiddenGroup (w, 2, 0, NULL);
13233     b = DefaultButton (c, "Accept", DoApplySetType);
13234     SetObjectExtra (b, bsfp, NULL);
13235     PushButton (c, "Cancel", StdCancelButtonProc);
13236     AlignObjects (ALIGN_CENTER, (HANDLE) h, (HANDLE) c, NULL);
13237     RealizeWindow (w);
13238     Show (w);
13239     Select (w);
13240   }
13241 }
13242 
13243 
13244 
BioseqSetEditFunc(Pointer data)13245 extern Int2 LIBCALLBACK BioseqSetEditFunc (Pointer data)
13246 
13247 {
13248   BioseqSetPtr      bssp;
13249   OMProcControlPtr  ompcp;
13250   ForM              w;
13251 
13252   ompcp = (OMProcControlPtr) data;
13253   bssp = NULL;
13254   if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
13255   switch (ompcp->input_itemtype) {
13256     case OBJ_BIOSEQSET :
13257       bssp = (BioseqSetPtr) ompcp->input_data;
13258       break;
13259    case 0 :
13260       break;
13261     default :
13262       return OM_MSG_RET_ERROR;
13263   }
13264   /* if (bssp == NULL) return OM_MSG_RET_ERROR; */
13265 
13266   w = CreateBioseqSetEditForm (bssp, ompcp->input_entityID);
13267   Show (w);
13268   Select (w);
13269   return OM_MSG_RET_DONE;
13270 }
13271 
13272 /*#ifdef EXTRA_SERVICES*/
13273 
13274 static CharPtr block_names[] = {
13275   "Unknown Block Type",
13276   "HEAD",
13277   "LOCUS",
13278   "DEFLINE",
13279   "ACCESSION",
13280   "VERSION",
13281   "PROJECT",
13282   "PID",
13283   "DBSOURCE",
13284   "DATE",
13285   "KEYWORDS",
13286   "SEGMENT",
13287   "SOURCE",
13288   "ORGANISM",
13289   "REF_STATS",
13290   "REFERENCE",
13291   "PRIMARY",
13292   "COMMENT",
13293   "FEAT_STATS",
13294   "FEATHEADER",
13295   "SOURCEFEAT",
13296   "FEATURE",
13297   "BASECOUNT",
13298   "ORIGIN",
13299   "SEQUENCE",
13300   "CONTIG",
13301   "WGS",
13302   "GENOME",
13303   "SLASH",
13304   "TAIL"
13305 };
13306 
CategorizeSUCBlocks(ValNodePtr head)13307 extern ValNodePtr CategorizeSUCBlocks (ValNodePtr head)
13308 {
13309   ValNodePtr vnp, next_vnp, category_list = NULL, new_list = NULL;
13310   ClickableItemPtr cip, first_cip;
13311 
13312   vnp = head;
13313   category_list = head;
13314   while (vnp != NULL && vnp->next != NULL) {
13315     next_vnp = vnp->next;
13316     if (vnp->choice != next_vnp->choice) {
13317       if (vnp->choice == FEATHEADER_BLOCK
13318           || vnp->choice == SLASH_BLOCK) {
13319         /* remove these blocktypes */
13320         vnp->next = NULL;
13321         category_list = FreeClickableList (category_list);
13322       } else {
13323         /* create a category to hold this blocktypes */
13324         first_cip = category_list->data.ptrvalue;
13325         cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
13326         MemSet (cip, 0, sizeof (ClickableItemData));
13327         cip->clickable_item_type = first_cip->clickable_item_type;
13328         cip->description = StringSave (block_names[first_cip->clickable_item_type]);
13329         vnp->next = NULL;
13330         cip->subcategories = category_list;
13331         ValNodeAddPointer (&new_list, vnp->choice, cip);
13332       }
13333       category_list = next_vnp;
13334     }
13335     vnp = next_vnp;
13336   }
13337   if (category_list != NULL) {
13338     if (category_list->choice == FEATHEADER_BLOCK
13339         || category_list->choice == SLASH_BLOCK) {
13340       category_list = FreeClickableList (category_list);
13341     } else {
13342       first_cip = category_list->data.ptrvalue;
13343       cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
13344       MemSet (cip, 0, sizeof (ClickableItemData));
13345       cip->clickable_item_type = first_cip->clickable_item_type;
13346       cip->description = StringSave (block_names[cip->clickable_item_type]);
13347       vnp->next = NULL;
13348       cip->subcategories = category_list;
13349       category_list = NULL;
13350       ValNodeAddPointer (&new_list, vnp->choice, cip);
13351     }
13352   }
13353   return new_list;
13354 }
13355 
13356 
13357 typedef struct resucoptions
13358 {
13359   Boolean     reverse;
13360   Boolean     byblock;
13361   Boolean     showsequence;
13362   Uint2       entityID;
13363 } ReSUCOptionsData, PNTR ReSUCOptionsPtr;
13364 
ReSUCFree(Pointer userdata)13365 static Pointer ReSUCFree (Pointer userdata)
13366 {
13367   return MemFree (userdata);
13368 }
13369 
ReSUCCallback(Pointer userdata)13370 static CharPtr ReSUCCallback (Pointer userdata)
13371 {
13372   ReSUCOptionsPtr rp;
13373   SeqEntryPtr     sep;
13374   FILE            *fp;
13375   ValNodePtr      head = NULL;
13376   Char            path [PATH_MAX];
13377   CharPtr         str;
13378   ValNodePtr      vnp;
13379   ClickableItemPtr cip;
13380 
13381   if (userdata == NULL)
13382   {
13383     return NULL;
13384   }
13385 
13386   rp = (ReSUCOptionsPtr) userdata;
13387 
13388   sep = GetTopSeqEntryForEntityID (rp->entityID);
13389   if (sep == NULL) return NULL;
13390 
13391   head = GetSUCCommonList (sep, rp->reverse, rp->byblock, rp->showsequence, FALSE);
13392 
13393   if (head != NULL) {
13394     TmpNam (path);
13395     fp = FileOpen (path, "w");
13396     if (fp != NULL) {
13397       for (vnp = head; vnp != NULL; vnp = vnp->next) {
13398         cip = (ClickableItemPtr) vnp->data.ptrvalue;
13399         str = cip->description;
13400         fprintf (fp, "%s\n", str);
13401       }
13402       FileClose (fp);
13403       return StringSave (path);
13404     }
13405   }
13406   return NULL;
13407 }
13408 
SUCBaseForm(BaseFormPtr bfp,Boolean reverse,Boolean byblock,Boolean showsequence,Boolean use_new_suc)13409 static void SUCBaseForm (BaseFormPtr bfp, Boolean reverse, Boolean byblock,
13410                              Boolean showsequence, Boolean use_new_suc)
13411 {
13412   FILE         *fp;
13413   ValNodePtr   head = NULL;
13414   Char         path [PATH_MAX];
13415   SeqEntryPtr  sep;
13416   CharPtr      str;
13417   ValNodePtr   vnp;
13418   ReSUCOptionsPtr rp = NULL;
13419   ClickableItemPtr cip;
13420 
13421   if (bfp == NULL) return;
13422   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
13423   if (sep == NULL) return;
13424   WatchCursor ();
13425   Update ();
13426   head = GetSUCCommonList (sep, reverse, byblock, showsequence, use_new_suc);
13427 
13428   if (head != NULL) {
13429     if (use_new_suc) {
13430       NewSUC (head, bfp->input_entityID, reverse, byblock, showsequence);
13431     } else {
13432       TmpNam (path);
13433       fp = FileOpen (path, "w");
13434       if (fp != NULL) {
13435         for (vnp = head; vnp != NULL; vnp = vnp->next) {
13436           cip = (ClickableItemPtr) vnp->data.ptrvalue;
13437           str = cip->description;
13438           fprintf (fp, "%s\n", str);
13439         }
13440         FileClose (fp);
13441       }
13442 
13443       rp = (ReSUCOptionsPtr) MemNew (sizeof (ReSUCOptionsData));
13444       if (rp != NULL)
13445       {
13446         rp->reverse = reverse;
13447         rp->byblock = byblock;
13448         rp->showsequence = showsequence;
13449         rp->entityID = bfp->input_entityID;
13450         LaunchGeneralTextViewerWithRepopulate (path, "Sort Unique Count",
13451                                                ReSUCCallback, rp, ReSUCFree);
13452       }
13453       else
13454       {
13455         LaunchGeneralTextViewer (path, "Sort Unique Count");
13456       }
13457 
13458       FileRemove (path);
13459       ValNodeFreeData (head);
13460     }
13461   }
13462   ArrowCursor ();
13463   Update ();
13464 }
13465 
SUCCommonProcEx(IteM i,Boolean reverse,Boolean byblock,Boolean showsequence,ButtoN b,Boolean use_new_suc)13466 static void SUCCommonProcEx (IteM i, Boolean reverse, Boolean byblock,
13467                              Boolean showsequence, ButtoN b, Boolean use_new_suc)
13468 
13469 {
13470   BaseFormPtr  bfp;
13471 
13472   if (b != NULL) {
13473     bfp = GetObjectExtra (b);
13474   } else {
13475 #ifdef WIN_MAC
13476     bfp = currentFormDataPtr;
13477 #else
13478     bfp = GetObjectExtra (i);
13479 #endif
13480   }
13481 
13482   SUCBaseForm (bfp, reverse, byblock, showsequence, use_new_suc);
13483 }
13484 
SUCCommonProc(IteM i,Boolean reverse,Boolean byblock,Boolean showsequence,ButtoN b)13485 static void SUCCommonProc (IteM i, Boolean reverse, Boolean byblock,
13486                            Boolean showsequence, ButtoN b)
13487 {
13488   SUCCommonProcEx (i, reverse, byblock, showsequence, b, FALSE);
13489 }
13490 
SUCProc(IteM i)13491 static void SUCProc (IteM i)
13492 
13493 {
13494   SUCCommonProc (i, FALSE, FALSE, TRUE, NULL);
13495 }
13496 
SUCRProc(IteM i)13497 static void SUCRProc (IteM i)
13498 
13499 {
13500   SUCCommonProc (i, TRUE, FALSE, TRUE, NULL);
13501 }
13502 
SUCBProc(IteM i)13503 static void SUCBProc (IteM i)
13504 
13505 {
13506   SUCCommonProc (i, FALSE, TRUE, TRUE, NULL);
13507 }
13508 
SUCBNoSequenceProc(IteM i)13509 static void SUCBNoSequenceProc (IteM i)
13510 
13511 {
13512   SUCCommonProc (i, FALSE, TRUE, FALSE, NULL);
13513 }
13514 
SUCSubmitterProc(IteM i)13515 extern void SUCSubmitterProc (IteM i)
13516 
13517 {
13518   SUCCommonProc (i, FALSE, TRUE, TRUE, NULL);
13519 }
13520 
13521 
SUCClickableProc(IteM i)13522 static void SUCClickableProc (IteM i)
13523 
13524 {
13525   SUCCommonProcEx (i, FALSE, TRUE, TRUE, NULL, TRUE);
13526 }
13527 
SUCClickableNoSequenceProc(IteM i)13528 static void SUCClickableNoSequenceProc (IteM i)
13529 
13530 {
13531   SUCCommonProcEx (i, FALSE, TRUE, FALSE, NULL, TRUE);
13532 }
13533 
13534 /*#endif*/
13535 
13536 #if 0
13537 #ifdef OS_UNIX
13538 extern void SUCCommonProc (IteM i, Boolean reverse, ButtoN b);
13539 extern void SUCCommonProc (IteM i, Boolean reverse, ButtoN b)
13540 
13541 {
13542   BaseFormPtr  bfp;
13543   Char         cmmd [256];
13544   FILE         *fp;
13545   ErrSev       level;
13546   Boolean      okay;
13547   SeqEntryPtr  oldscope;
13548   Char         path [PATH_MAX];
13549   SeqEntryPtr  sep;
13550 
13551   if (b != NULL) {
13552     bfp = GetObjectExtra (b);
13553   } else {
13554 #ifdef WIN_MAC
13555     bfp = currentFormDataPtr;
13556 #else
13557     bfp = GetObjectExtra (i);
13558 #endif
13559   }
13560   if (bfp == NULL) return;
13561   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
13562   if (sep == NULL) return;
13563   TmpNam (path);
13564   fp = FileOpen (path, "w");
13565   if (fp == NULL) return;
13566   WatchCursor ();
13567   Update ();
13568   level = ErrSetMessageLevel (SEV_MAX);
13569   oldscope = SeqEntrySetScope (sep);
13570   okay = SeqEntryToGnbk (sep, NULL, GENBANK_FMT, SEQUIN_MODE, NORMAL_STYLE, 0, 0, 0, NULL, fp);
13571   SeqEntrySetScope (oldscope);
13572   ErrSetMessageLevel (level);
13573   FileClose (fp);
13574   if (okay) {
13575     if (reverse) {
13576       sprintf (cmmd, "sort %s | uniq -c | sort -nr > %s.suc; rm %s", path, path, path);
13577     } else {
13578       sprintf (cmmd, "sort %s | uniq -c > %s.suc; rm %s", path, path, path);
13579     }
13580     system (cmmd); /* removes original flat file */
13581     StringCat (path, ".suc");
13582     LaunchGeneralTextViewer (path, "Sort Unique Count");
13583     FileRemove (path); /* removes sorted/uniqued/counted file */
13584   } else {
13585     FileRemove (path);
13586   }
13587   ArrowCursor ();
13588   Update ();
13589 }
13590 
13591 static void SUCProc (IteM i)
13592 
13593 {
13594   SUCCommonProc (i, FALSE, NULL);
13595 }
13596 
13597 static void SUCRProc (IteM i)
13598 
13599 {
13600   SUCCommonProc (i, TRUE, NULL);
13601 }
13602 #endif
13603 #endif
13604 
13605 /*#ifdef INTERNAL_NCBI_SEQUIN*/
13606 /*#ifdef NEW_TAXON_SERVICE*/
13607 /*
13608 *  Get top 900 organisms, remove all ending with 'sp.',
13609 *  all starting with unknown, unidentified, uncultured,
13610 *  unclassified, cloning vector, synthetic construct,
13611 *  mixed EST library, also remove Rattus rattus,
13612 *  trim to remaining 800 organisms, remove any counts
13613 *
13614 *  Process output in UNIX with
13615 *    'sort -f +0 sorttax | uniq > taxlist.txt'
13616 *  and
13617 *    'sort -n +0 sortlin | uniq > lineages.txt'
13618 *
13619 *  Then add version number to top of each file
13620 */
13621 
WriteTaxNode(CharPtr sci,CharPtr com,CharPtr syn,Int4 gc,Int4 mgc,CharPtr div,Int4 taxID,FILE * fout)13622 static Boolean WriteTaxNode (CharPtr sci, CharPtr com, CharPtr syn,
13623                              Int4 gc, Int4 mgc, CharPtr div,
13624                              Int4 taxID, FILE *fout)
13625 
13626 {
13627   Char  str [256];
13628 
13629   if (fout == NULL) return FALSE;
13630   if (sci != NULL && sci [0] != '\0') {
13631     if (div == NULL || div [0] == '\0') div = "???";
13632     if (com != NULL && com [0] != '\0') {
13633       sprintf (str, "%s\t%s\t%ld\t%ld\t%s\t%ld\n", sci, com,
13634                (long) gc, (long) mgc, div, (long) taxID);
13635       fprintf (fout, "%s", str);
13636     } else {
13637       sprintf (str, "%s\t\t%ld\t%ld\t%s\t%ld\n", sci,
13638                (long) gc, (long) mgc, div, (long) taxID);
13639       fprintf (fout, "%s", str);
13640     }
13641     return TRUE;
13642   }
13643   return FALSE;
13644 }
13645 
WriteLineage(Int4 taxID,CharPtr lineage,FILE * fout)13646 static void WriteLineage (Int4 taxID, CharPtr lineage, FILE *fout)
13647 
13648 {
13649   if (fout == NULL || lineage == NULL) return;
13650   fprintf (fout, "%ld\t%s\n", (long) taxID, lineage);
13651 }
13652 
ProcessTaxNode(OrgRefPtr orp,FILE * fout1,FILE * fout2)13653 static void ProcessTaxNode (OrgRefPtr orp, FILE *fout1, FILE *fout2)
13654 
13655 {
13656   Int4           gc;
13657   Int4           mgc;
13658   OrgModPtr      omp;
13659   OrgNamePtr     onp;
13660   Int4           taxID = -1;
13661   DbtagPtr       d;
13662   ValNodePtr     vnp;
13663   CharPtr        div = NULL;
13664 
13665   if (orp == NULL || fout1 == NULL || fout2 == NULL) return;
13666 
13667   for (vnp = orp->db; vnp != NULL; vnp = vnp->next)
13668   {
13669     d = (DbtagPtr) vnp->data.ptrvalue;
13670     if (StringCmp(d->db, "taxon") == 0)
13671     {
13672       taxID = d->tag->id;
13673       break;
13674     }
13675   }
13676   if (taxID > -1)
13677   {
13678     gc = 0;
13679     mgc = 0;
13680     onp = orp->orgname;
13681     if (onp != NULL)
13682     {
13683       gc = onp->gcode;
13684       mgc = onp->mgcode;
13685       div = onp->div;
13686     }
13687     if (WriteTaxNode (orp->taxname, orp->common, NULL, gc, mgc, div, taxID, fout1))
13688     {
13689       if (onp != NULL)
13690       {
13691         WriteLineage (taxID, onp->lineage, fout2);
13692         for (omp = onp->mod; omp != NULL; omp = omp->next)
13693         {
13694           if (omp->subtype == ORGMOD_gb_anamorph ||
13695             omp->subtype == ORGMOD_gb_synonym)
13696           {
13697             WriteTaxNode (omp->subname, orp->common, NULL, gc, mgc, div, taxID, fout1);
13698           }
13699         }
13700       }
13701     }
13702   }
13703 }
13704 
PrepareTaxListProc(IteM i)13705 static void PrepareTaxListProc (IteM i)
13706 
13707 {
13708   Char     ch;
13709   FILE     *fin;
13710   FILE     *fout1;
13711   FILE     *fout2;
13712   Boolean  goOn;
13713   Char     orgname [256];
13714   CharPtr  ptr;
13715   ValNodePtr org_list = NULL;
13716   ValNodePtr response_list = NULL;
13717   ValNodePtr vnp;
13718   OrgRefPtr  orp;
13719 
13720   orgname [0] = '\0';
13721   goOn = TRUE;
13722   Message (MSG_POST, "Finding File");
13723   fin = FileOpen ("orglist", "r");
13724   if (fin != NULL) {
13725     fout1 = FileOpen ("sorttax", "w");
13726     if (fout1 != NULL) {
13727       fout2 = FileOpen ("sortlin", "w");
13728       if (fout2 != NULL) {
13729         Message (MSG_POST, "Processing");
13730         while (goOn) {
13731           goOn = (FileGets (orgname, sizeof (orgname), fin) != NULL);
13732           if (goOn) {
13733             ptr = orgname;
13734             ch = *ptr;
13735             while (ch != '\n' && ch != '\r' && ch != '\0') {
13736               ptr++;
13737               ch = *ptr;
13738             }
13739             *ptr = '\0';
13740             Message (MSG_POST, "Organism '%s'", orgname);
13741             ValNodeCopyStr (&org_list, 2, orgname);
13742           }
13743         }
13744         Message (MSG_POST, "Retrieving from server");
13745         response_list =  Taxon3GetOrgRefList (org_list);
13746         for (vnp = response_list; vnp != NULL; vnp = vnp->next)
13747         {
13748           orp = (OrgRefPtr) vnp->data.ptrvalue;
13749           ProcessTaxNode (orp, fout1, fout2);
13750           vnp->data.ptrvalue = OrgRefFree (orp);
13751         }
13752         response_list = ValNodeFree (response_list);
13753         org_list = ValNodeFreeData (org_list);
13754 
13755         FileClose (fout2);
13756 
13757       }
13758       FileClose (fout1);
13759     }
13760     FileClose (fin);
13761   } else {
13762     Message (MSG_OK, "Could not find orglist file");
13763   }
13764 
13765   Message (MSG_POST, "Finished");
13766 }
13767 /*#endif*/
13768 /*#endif*/
13769 
13770 
13771 #define REMOVE_PUB   1
13772 
ENUM_ALIST(pub_field_alist)13773 static ENUM_ALIST(pub_field_alist)
13774   {" ",                    0},
13775   {"Remark",               1},
13776 END_ENUM_ALIST
13777 
13778 typedef struct pubformdata {
13779   FEATURE_FORM_BLOCK
13780 
13781   Int2           type;
13782   PopuP          fromfield;
13783   Int2           fromval;
13784   ButtoN         removeIncompletePubs;
13785 } PubFormData, PNTR PubFormPtr;
13786 
ProcessEachPubFunc(GatherContextPtr gcp)13787 static Boolean ProcessEachPubFunc (GatherContextPtr gcp)
13788 
13789 {
13790   PubdescPtr  pdp;
13791   PubFormPtr  pfp;
13792   ValNodePtr  sdp;
13793   SeqFeatPtr  sfp;
13794 
13795   if (gcp == NULL) return TRUE;
13796   pfp = (PubFormPtr) gcp->userdata;
13797   if (pfp == NULL) return TRUE;
13798   pdp = NULL;
13799   if (gcp->thistype == OBJ_SEQDESC) {
13800     sdp = (ValNodePtr) gcp->thisitem;
13801     if (sdp != NULL && sdp->choice == Seq_descr_pub) {
13802       pdp = (PubdescPtr) sdp->data.ptrvalue;
13803     }
13804   } else if (gcp->thistype == OBJ_SEQFEAT) {
13805     sfp = (SeqFeatPtr) gcp->thisitem;
13806     if (sfp != NULL && sfp->data.choice == SEQFEAT_PUB) {
13807       pdp = (PubdescPtr) sfp->data.value.ptrvalue;
13808     }
13809   }
13810   if (pdp == NULL) return TRUE;
13811   switch (pfp->fromval) {
13812     case 1 :
13813       pdp->comment = MemFree (pdp->comment);
13814       break;
13815     default :
13816       break;
13817   }
13818   return TRUE;
13819 }
13820 
13821 /* PubdescIsIncomplete modified from ValidatePubdesc in valid.c */
HasNoText(CharPtr str)13822 static Boolean HasNoText (CharPtr str)
13823 
13824 {
13825   Char  ch;
13826 
13827   if (str != NULL) {
13828     ch = *str;
13829     while (ch != '\0') {
13830       if (ch > ' ') {
13831         return FALSE;
13832       }
13833       str++;
13834       ch = *str;
13835     }
13836   }
13837   return TRUE;
13838 }
13839 
HasNoName(ValNodePtr name)13840 static Boolean HasNoName (ValNodePtr name)
13841 
13842 {
13843 	AuthorPtr  ap;
13844 	NameStdPtr  nsp;
13845 	PersonIdPtr  pid;
13846 
13847 	if (name != NULL) {
13848 		ap = name->data.ptrvalue;
13849 		if (ap != NULL) {
13850 			pid = ap->name;
13851 			if (pid != NULL) {
13852 				if (pid->choice == 2) {
13853 					nsp = pid->data;
13854 					if (nsp != NULL) {
13855 						if (! HasNoText (nsp->names [0])) {
13856 							return FALSE;
13857 						}
13858 					}
13859 				}
13860 			}
13861 		}
13862 	}
13863 	return TRUE;
13864 }
13865 
PubdescIsIncomplete(PubdescPtr pdp)13866 static Boolean PubdescIsIncomplete (PubdescPtr pdp)
13867 
13868 {
13869 	AuthListPtr  alp;
13870 	CitArtPtr  cap;
13871 	Boolean  hasName, hasTitle;
13872 	ValNodePtr  name;
13873 	ValNodePtr  title;
13874 	ValNodePtr  vnp;
13875 
13876 	if (pdp == NULL) return TRUE;
13877 	for (vnp = pdp->pub; vnp != NULL; vnp = vnp->next) {
13878 		switch (vnp->choice) {
13879 			case PUB_Article :
13880 				cap = (CitArtPtr) vnp->data.ptrvalue;
13881 				hasName = FALSE;
13882 				hasTitle = FALSE;
13883 				if (cap != NULL) {
13884 					for (title = cap->title; title != NULL; title = title->next) {
13885 						if (! HasNoText ((CharPtr) title->data.ptrvalue)) {
13886 							hasTitle = TRUE;
13887 						}
13888 					}
13889 					if (! hasTitle) {
13890 						return TRUE;
13891 					}
13892 					alp = cap->authors;
13893 					if (alp != NULL) {
13894 						if (alp->choice == 1) {
13895 							for (name = alp->names; name != NULL; name = name->next) {
13896 								if (! HasNoName (name)) {
13897 									hasName = TRUE;
13898 								}
13899 							}
13900 						} else if (alp->choice == 2 || alp->choice == 3) {
13901 							for (name = alp->names; name != NULL; name = name->next) {
13902 								if (! HasNoText ((CharPtr) name->data.ptrvalue)) {
13903 									hasName = TRUE;
13904 								}
13905 							}
13906 						}
13907 					}
13908 					if (! hasName) {
13909 						return TRUE;
13910 					}
13911 				}
13912 				break;
13913 			default :
13914 				break;
13915 		}
13916 	}
13917 	return FALSE;
13918 }
13919 
RemoveIncompletePubs(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)13920 static void RemoveIncompletePubs (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
13921 
13922 {
13923   BioseqPtr     bsp;
13924   BioseqSetPtr  bssp;
13925   Boolean       empty;
13926   SeqAnnotPtr   nextsap;
13927   ValNodePtr    nextsdp;
13928   SeqFeatPtr    nextsfp;
13929   PubdescPtr    pdp;
13930   Pointer PNTR  prevsap;
13931   Pointer PNTR  prevsdp;
13932   Pointer PNTR  prevsfp;
13933   SeqAnnotPtr   sap;
13934   ValNodePtr    sdp;
13935   SeqFeatPtr    sfp;
13936 
13937   if (sep == NULL || sep->data.ptrvalue == NULL) return;
13938   if (IS_Bioseq (sep)) {
13939     bsp = (BioseqPtr) sep->data.ptrvalue;
13940     sdp = bsp->descr;
13941     prevsdp = (Pointer PNTR) &(bsp->descr);
13942     sap = bsp->annot;
13943     prevsap = (Pointer PNTR) &(bsp->annot);
13944   } else if (IS_Bioseq_set (sep)) {
13945     bssp = (BioseqSetPtr) sep->data.ptrvalue;
13946     sdp = bssp->descr;
13947     prevsdp = (Pointer PNTR) &(bssp->descr);
13948     sap = bssp->annot;
13949     prevsap = (Pointer PNTR) &(bssp->annot);
13950   } else return;
13951   while (sap != NULL) {
13952     nextsap = sap->next;
13953     if (sap->type == 1) {
13954       sfp = (SeqFeatPtr) sap->data;
13955       prevsfp = (Pointer PNTR) &(sap->data);
13956       while (sfp != NULL) {
13957         nextsfp = sfp->next;
13958         empty = FALSE;
13959         if (sfp->data.choice == SEQFEAT_PUB && sfp->data.value.ptrvalue != NULL) {
13960           pdp = (PubdescPtr) sfp->data.value.ptrvalue;
13961           empty = PubdescIsIncomplete (pdp);
13962         }
13963         if (empty) {
13964           *(prevsfp) = sfp->next;
13965           sfp->next = NULL;
13966           SeqFeatFree (sfp);
13967         } else {
13968           prevsfp = (Pointer PNTR) &(sfp->next);
13969         }
13970         sfp = nextsfp;
13971       }
13972     }
13973     if (sap->data == NULL) {
13974       *(prevsap) = sap->next;
13975       sap->next = NULL;
13976       SeqAnnotFree (sap);
13977     } else {
13978       prevsap = (Pointer PNTR) &(sap->next);
13979     }
13980     sap = nextsap;
13981   }
13982   while (sdp != NULL) {
13983     nextsdp = sdp->next;
13984     empty = FALSE;
13985     if (sdp->choice == Seq_descr_pub) {
13986       pdp = (PubdescPtr) sdp->data.ptrvalue;
13987       empty = PubdescIsIncomplete (pdp);
13988     }
13989     if (empty) {
13990       *(prevsdp) = sdp->next;
13991       sdp->next = NULL;
13992       SeqDescFree (sdp);
13993     } else {
13994       prevsdp = (Pointer PNTR) &(sdp->next);
13995     }
13996     sdp = nextsdp;
13997   }
13998 }
13999 
DoProcessPub(ButtoN b)14000 static void DoProcessPub (ButtoN b)
14001 
14002 {
14003   PubFormPtr   pfp;
14004   GatherScope  gs;
14005   SeqEntryPtr  sep;
14006   UIEnum       val;
14007 
14008   pfp = (PubFormPtr) GetObjectExtra (b);
14009   if (pfp == NULL || pfp->input_entityID == 0) return;
14010   Hide (pfp->form);
14011   WatchCursor ();
14012   Update ();
14013   pfp->fromval = 0;
14014   if (GetEnumPopup (pfp->fromfield, pub_field_alist, &val)) {
14015     pfp->fromval = (Int2) val;
14016   }
14017   MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
14018   gs.seglevels = 1;
14019   gs.get_feats_location = FALSE;
14020   MemSet((Pointer)(gs.ignore), (int)(TRUE), (size_t)(OBJ_MAX * sizeof(Boolean)));
14021   gs.ignore[OBJ_BIOSEQ] = FALSE;
14022   gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
14023   gs.ignore[OBJ_SEQFEAT] = FALSE;
14024   gs.ignore[OBJ_SEQANNOT] = FALSE;
14025   gs.ignore[OBJ_SEQDESC] = FALSE;
14026   GatherEntity (pfp->input_entityID, (Pointer) pfp, ProcessEachPubFunc, &gs);
14027   if (GetStatus (pfp->removeIncompletePubs)) {
14028     sep = GetTopSeqEntryForEntityID (pfp->input_entityID);
14029     if (sep != NULL) {
14030       SeqEntryExplore (sep, NULL, RemoveIncompletePubs);
14031     }
14032   }
14033   ArrowCursor ();
14034   Update ();
14035   ObjMgrSetDirtyFlag (pfp->input_entityID, TRUE);
14036   ObjMgrSendMsg (OM_MSG_UPDATE, pfp->input_entityID, 0, 0);
14037   ObjMgrDeSelect (0, 0, 0, 0, NULL);
14038   Remove (pfp->form);
14039 }
14040 
PubMessageProc(ForM f,Int2 mssg)14041 static void PubMessageProc (ForM f, Int2 mssg)
14042 
14043 {
14044   PubFormPtr  pfp;
14045 
14046   pfp = (PubFormPtr) GetObjectExtra (f);
14047   if (pfp != NULL) {
14048     if (pfp->appmessage != NULL) {
14049       pfp->appmessage (f, mssg);
14050     }
14051   }
14052 }
14053 
ProcessPub(IteM i,Int2 type)14054 static void ProcessPub (IteM i, Int2 type)
14055 
14056 {
14057   ButtoN             b;
14058   BaseFormPtr        bfp;
14059   GrouP              c;
14060   GrouP              g;
14061   GrouP              h;
14062   PubFormPtr         pfp;
14063   SeqEntryPtr        sep;
14064   StdEditorProcsPtr  sepp;
14065   CharPtr            title;
14066   WindoW             w;
14067 
14068 #ifdef WIN_MAC
14069   bfp = currentFormDataPtr;
14070 #else
14071   bfp = GetObjectExtra (i);
14072 #endif
14073   if (bfp == NULL) return;
14074   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14075   if (sep == NULL) return;
14076   pfp = (PubFormPtr) MemNew (sizeof (PubFormData));
14077   if (pfp == NULL) return;
14078   pfp->type = type;
14079   switch (type) {
14080     case REMOVE_PUB :
14081       title = "Pub Removal";
14082       break;
14083     default :
14084       title = "?";
14085       break;
14086   }
14087   w = FixedWindow (-50, -33, -10, -10, title, StdCloseWindowProc);
14088   SetObjectExtra (w, pfp, StdCleanupFormProc);
14089   pfp->form = (ForM) w;
14090   pfp->formmessage = PubMessageProc;
14091 
14092   sepp = (StdEditorProcsPtr) GetAppProperty ("StdEditorForm");
14093   if (sepp != NULL) {
14094     SetActivate (w, sepp->activateForm);
14095     pfp->appmessage = sepp->handleMessages;
14096   }
14097 
14098   pfp->input_entityID = bfp->input_entityID;
14099   pfp->input_itemID = bfp->input_itemID;
14100   pfp->input_itemtype = bfp->input_itemtype;
14101 
14102   h = HiddenGroup (w, -1, 0, NULL);
14103   SetGroupSpacing (h, 10, 10);
14104 
14105   g = HiddenGroup (h, 4, 0, NULL);
14106   switch (type) {
14107     case REMOVE_PUB :
14108       StaticPrompt (g, "Remove", 0, popupMenuHeight, programFont, 'l');
14109       pfp->fromfield = PopupList (g, TRUE, NULL);
14110       SetObjectExtra (pfp->fromfield, pfp, NULL);
14111       InitEnumPopup (pfp->fromfield, pub_field_alist, NULL);
14112       SetEnumPopup (pfp->fromfield, pub_field_alist, 0);
14113       break;
14114     default :
14115       break;
14116   }
14117 
14118   pfp->removeIncompletePubs = NULL;
14119   if (type == REMOVE_PUB) {
14120     pfp->removeIncompletePubs = CheckBox (h, "Remove Incomplete Publications", NULL);
14121   }
14122 
14123   c = HiddenGroup (h, 4, 0, NULL);
14124   b = DefaultButton (c, "Accept", DoProcessPub);
14125   SetObjectExtra (b, pfp, NULL);
14126   PushButton (c, "Cancel", StdCancelButtonProc);
14127 
14128   AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, (HANDLE) pfp->removeIncompletePubs, NULL);
14129   RealizeWindow (w);
14130   Show (w);
14131   Update ();
14132 }
14133 
RemovePub(IteM i)14134 static void RemovePub (IteM i)
14135 
14136 {
14137   ProcessPub (i, REMOVE_PUB);
14138 }
14139 
SequinSetPubScratchData(SeqDescrPtr sdp,Pointer userdata)14140 static void SequinSetPubScratchData (SeqDescrPtr sdp, Pointer userdata)
14141 
14142 {
14143   AuthListPtr    alp;
14144   Char           buf [2048];
14145   CitGenPtr      cgp;
14146   CharPtr        consortium, str, tmp;
14147   ValNodePtr     vnp;
14148   ObjValNodePtr  ovp;
14149   PubdescPtr     pdp;
14150 
14151   if (sdp == NULL || sdp->choice != Seq_descr_pub || sdp->extended == 0) return;
14152   ovp = (ObjValNodePtr) sdp;
14153   pdp = (PubdescPtr) sdp->data.ptrvalue;
14154   if (pdp == NULL) return;
14155 
14156   vnp = pdp->pub;
14157 
14158   /* skip over just serial number */
14159 
14160   if (vnp != NULL && vnp->choice == PUB_Gen && vnp->next != NULL) {
14161     cgp = (CitGenPtr) vnp->data.ptrvalue;
14162     if (cgp != NULL) {
14163       if (StringNICmp ("BackBone id_pub", cgp->cit, 15) != 0) {
14164         if (cgp->cit == NULL && cgp->journal == NULL && cgp->date == NULL && cgp->serial_number) {
14165           vnp = vnp->next;
14166         }
14167       }
14168     }
14169   }
14170 
14171   if (PubLabelUnique (vnp, buf, sizeof (buf) - 1, OM_LABEL_CONTENT, TRUE) > 0) {
14172     alp = GetAuthListPtr (pdp, NULL);
14173     if (alp != NULL) {
14174       consortium = NULL;
14175       str = GetAuthorsString (GENBANK_FMT, alp, &consortium, NULL, NULL);
14176       if (StringDoesHaveText (buf) || StringDoesHaveText (str) || StringDoesHaveText (consortium)) {
14177         tmp = MemNew (StringLen (buf) + StringLen (str) + StringLen (consortium) + 10);
14178         if (tmp != NULL) {
14179           StringCpy (tmp, buf);
14180           if (StringDoesHaveText (str)) {
14181             StringCat (tmp, "; ");
14182             StringCat (tmp, str);
14183           }
14184           if (StringDoesHaveText (consortium)) {
14185             StringCat (tmp, "; ");
14186             StringCat (tmp, consortium);
14187           }
14188           ovp->idx.scratch = tmp;
14189         }
14190       }
14191       MemFree (str);
14192       MemFree (consortium);
14193     }
14194   }
14195 }
14196 
SequinClearPubScratchData(SeqDescrPtr sdp,Pointer userdata)14197 static void SequinClearPubScratchData (SeqDescrPtr sdp, Pointer userdata)
14198 
14199 {
14200   ObjValNodePtr  ovp;
14201 
14202   if (sdp == NULL || sdp->choice != Seq_descr_pub || sdp->extended == 0) return;
14203   ovp = (ObjValNodePtr) sdp;
14204   ovp->idx.scratch = MemFree (ovp->idx.scratch);
14205 }
14206 
MarkCollidingPubs(BioseqPtr bsp,Pointer userdata)14207 static void MarkCollidingPubs (BioseqPtr bsp, Pointer userdata)
14208 
14209 {
14210   SeqMgrDescContext  dcontext;
14211   ValNodePtr         head = NULL, last = NULL, vnp, nxt;
14212   ObjValNodePtr      ovp, ovp1, ovp2;
14213   PubdescPtr         pdp;
14214   SeqDescrPtr        sdp;
14215   CharPtr            str1, str2;
14216 
14217   if (bsp == NULL) return;
14218   if (! ISA_na (bsp->mol)) return;
14219   if (SeqMgrGetParentOfPart (bsp, NULL) != NULL) return;
14220 
14221   sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_pub, &dcontext);
14222   while (sdp) {
14223     pdp = (PubdescPtr) sdp->data.ptrvalue;
14224     if (pdp != NULL) {
14225       ovp = (ObjValNodePtr) sdp;
14226       if (ovp->idx.scratch != NULL) {
14227         vnp = ValNodeAddPointer (&last, 0, (Pointer) ovp);
14228         if (head == NULL) {
14229           head = vnp;
14230         }
14231         last = vnp;
14232       }
14233     }
14234     sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_pub, &dcontext);
14235   }
14236 
14237   for (vnp = head; vnp != NULL; vnp = vnp->next) {
14238     ovp1 = (ObjValNodePtr) vnp->data.ptrvalue;
14239     if (ovp1 == NULL) continue;
14240     str1 = (CharPtr) ovp1->idx.scratch;
14241     if (StringHasNoText (str1)) continue;
14242     for (nxt = vnp->next; nxt != NULL; nxt = nxt->next) {
14243       ovp2 = (ObjValNodePtr) nxt->data.ptrvalue;
14244       if (ovp2 == NULL) continue;
14245       str2 = (CharPtr) ovp2->idx.scratch;
14246       if (StringHasNoText (str2)) continue;
14247       if (StringICmp (str1, str2) == 0) {
14248         ovp1->idx.deleteme = TRUE;
14249       }
14250     }
14251   }
14252 
14253   ValNodeFree (head);
14254 }
14255 
RemoveCollidingPublications(IteM i)14256 static void RemoveCollidingPublications (IteM i)
14257 
14258 {
14259   BaseFormPtr  bfp;
14260   SeqEntryPtr  sep;
14261 
14262 #ifdef WIN_MAC
14263   bfp = currentFormDataPtr;
14264 #else
14265   bfp = GetObjectExtra (i);
14266 #endif
14267   if (bfp == NULL) return;
14268   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14269   if (sep == NULL) return;
14270   VisitDescriptorsInSep (sep, NULL, SequinSetPubScratchData);
14271   VisitBioseqsInSep (sep, NULL, MarkCollidingPubs);
14272   VisitDescriptorsInSep (sep, NULL, SequinClearPubScratchData);
14273   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
14274   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14275   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14276 }
14277 
StripSerials(IteM i)14278 static void StripSerials (IteM i)
14279 
14280 {
14281   BaseFormPtr  bfp;
14282   SeqEntryPtr  sep;
14283 
14284 #ifdef WIN_MAC
14285   bfp = currentFormDataPtr;
14286 #else
14287   bfp = GetObjectExtra (i);
14288 #endif
14289   if (bfp == NULL) return;
14290   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14291   if (sep == NULL) return;
14292   EntryStripSerialNumber (sep);
14293   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14294   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14295 }
14296 
RemoveLocalIDsProc(SeqEntryPtr sep,Boolean do_nuc,Boolean do_prt)14297 static void RemoveLocalIDsProc (SeqEntryPtr sep, Boolean do_nuc, Boolean do_prt)
14298 
14299 {
14300   BioseqPtr     bsp;
14301   SeqIdPtr      nextsip;
14302   Pointer PNTR  prevsip;
14303   Boolean       replaced;
14304   SeqIdPtr      sip;
14305 
14306   if (sep == NULL) return;
14307   if (! IS_Bioseq (sep)) return;
14308   bsp = (BioseqPtr) sep->data.ptrvalue;
14309   if (bsp == NULL) return;
14310   if (ISA_na (bsp->mol) && (! do_nuc)) return;
14311   if (ISA_aa (bsp->mol) && (! do_prt)) return;
14312   sip = bsp->id;
14313   prevsip = (Pointer PNTR) &(bsp->id);
14314   replaced = FALSE;
14315   while (sip != NULL) {
14316     nextsip = sip->next;
14317     if (sip->choice == SEQID_LOCAL) {
14318       (*prevsip) = sip->next;
14319       sip->next = NULL;
14320       SeqIdFree (sip);
14321       replaced = TRUE;
14322     } else {
14323       prevsip = (Pointer PNTR) &(sip->next);
14324     }
14325     sip = nextsip;
14326   }
14327   if (replaced) {
14328     SeqMgrReplaceInBioseqIndex (bsp);
14329   }
14330 }
14331 
RemoveAllLocalIDsProc(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)14332 static void RemoveAllLocalIDsProc (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
14333 
14334 {
14335   RemoveLocalIDsProc (sep, TRUE, TRUE);
14336 }
14337 
RemoveNucLocalIDsProc(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)14338 static void RemoveNucLocalIDsProc (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
14339 
14340 {
14341   RemoveLocalIDsProc (sep, TRUE, FALSE);
14342 }
14343 
RemovePrtLocalIDsProc(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)14344 static void RemovePrtLocalIDsProc (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
14345 
14346 {
14347   RemoveLocalIDsProc (sep, FALSE, TRUE);
14348 }
14349 
RemoveLocalIDs(IteM i)14350 static void RemoveLocalIDs (IteM i)
14351 
14352 {
14353   BaseFormPtr  bfp;
14354   SeqEntryPtr  sep;
14355 
14356 #ifdef WIN_MAC
14357   bfp = currentFormDataPtr;
14358 #else
14359   bfp = GetObjectExtra (i);
14360 #endif
14361   if (bfp == NULL) return;
14362   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14363   if (sep == NULL) return;
14364   SeqEntryExplore (sep, NULL, RemoveAllLocalIDsProc);
14365   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14366   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14367 }
14368 
RemoveNucLocalIDs(IteM i)14369 static void RemoveNucLocalIDs (IteM i)
14370 
14371 {
14372   BaseFormPtr  bfp;
14373   SeqEntryPtr  sep;
14374 
14375 #ifdef WIN_MAC
14376   bfp = currentFormDataPtr;
14377 #else
14378   bfp = GetObjectExtra (i);
14379 #endif
14380   if (bfp == NULL) return;
14381   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14382   if (sep == NULL) return;
14383   SeqEntryExplore (sep, NULL, RemoveNucLocalIDsProc);
14384   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14385   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14386 }
14387 
RemovePrtLocalIDs(IteM i)14388 static void RemovePrtLocalIDs (IteM i)
14389 
14390 {
14391   BaseFormPtr  bfp;
14392   SeqEntryPtr  sep;
14393 
14394 #ifdef WIN_MAC
14395   bfp = currentFormDataPtr;
14396 #else
14397   bfp = GetObjectExtra (i);
14398 #endif
14399   if (bfp == NULL) return;
14400   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14401   if (sep == NULL) return;
14402   SeqEntryExplore (sep, NULL, RemovePrtLocalIDsProc);
14403   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14404   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14405 }
14406 
14407 
IsTSAId(SeqIdPtr sip)14408 static Boolean IsTSAId (SeqIdPtr sip)
14409 {
14410   DbtagPtr dbtag;
14411 
14412   if (sip != NULL && sip->choice == SEQID_GENERAL
14413       && (dbtag = (DbtagPtr) sip->data.ptrvalue) != NULL
14414       && (StringNCmp (dbtag->db, "gpid:", 5) == 0 || StringNCmp (dbtag->db, "bpid:", 5) == 0))
14415   {
14416     return TRUE;
14417   }
14418   else
14419   {
14420     return FALSE;
14421   }
14422 }
14423 
14424 
RemoveTSAIdsProc(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)14425 static void RemoveTSAIdsProc (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
14426 
14427 {
14428   BioseqPtr     bsp;
14429   SeqIdPtr      nextsip;
14430   Pointer PNTR  prevsip;
14431   Boolean       replaced;
14432   SeqIdPtr      sip;
14433 
14434   if (sep == NULL) return;
14435   if (! IS_Bioseq (sep)) return;
14436   bsp = (BioseqPtr) sep->data.ptrvalue;
14437   if (bsp == NULL) return;
14438   sip = bsp->id;
14439   prevsip = (Pointer PNTR) &(bsp->id);
14440   replaced = FALSE;
14441   while (sip != NULL) {
14442     nextsip = sip->next;
14443     if (IsTSAId(sip)) {
14444       (*prevsip) = sip->next;
14445       sip->next = NULL;
14446       SeqIdFree (sip);
14447       replaced = TRUE;
14448     } else {
14449       prevsip = (Pointer PNTR) &(sip->next);
14450     }
14451     sip = nextsip;
14452   }
14453   if (replaced) {
14454     SeqMgrReplaceInBioseqIndex (bsp);
14455   }
14456 }
14457 
14458 
RemoveTSAIdsFromBioseqs(IteM i)14459 static void RemoveTSAIdsFromBioseqs (IteM i)
14460 
14461 {
14462   BaseFormPtr  bfp;
14463   SeqEntryPtr  sep;
14464 
14465 #ifdef WIN_MAC
14466   bfp = currentFormDataPtr;
14467 #else
14468   bfp = GetObjectExtra (i);
14469 #endif
14470   if (bfp == NULL) return;
14471   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14472   if (sep == NULL) return;
14473   SeqEntryExplore (sep, NULL, RemoveTSAIdsProc);
14474   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14475   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14476 }
14477 
14478 
RemoveLocusProc(BioseqPtr bsp,Pointer userdata)14479 static void RemoveLocusProc (BioseqPtr bsp, Pointer userdata)
14480 
14481 {
14482   Boolean       reindex = FALSE;
14483   SeqIdPtr      sip;
14484   TextSeqIdPtr  tsip;
14485 
14486   for (sip = bsp->id; sip != NULL; sip = sip->next) {
14487     switch (sip->choice) {
14488       case SEQID_GENBANK :
14489       case SEQID_EMBL :
14490       case SEQID_OTHER :
14491       case SEQID_DDBJ :
14492       case SEQID_TPG :
14493       case SEQID_TPE :
14494       case SEQID_TPD :
14495         tsip = (TextSeqIdPtr) sip->data.ptrvalue;
14496         if (tsip != NULL) {
14497           tsip->name = MemFree (tsip->name);
14498           reindex = TRUE;
14499         }
14500         break;
14501       default :
14502         break;
14503     }
14504   }
14505   if (reindex) {
14506     SeqMgrReplaceInBioseqIndex (bsp);
14507   }
14508 }
14509 
RemoveLocusFromParts(IteM i)14510 static void RemoveLocusFromParts (IteM i)
14511 
14512 {
14513   BaseFormPtr  bfp;
14514   SeqEntryPtr  sep;
14515 
14516 #ifdef WIN_MAC
14517   bfp = currentFormDataPtr;
14518 #else
14519   bfp = GetObjectExtra (i);
14520 #endif
14521   if (bfp == NULL) return;
14522   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14523   if (sep == NULL) return;
14524   if (Message (MSG_OKC, "Are you SURE you want to do this?") == ANS_CANCEL) return;
14525   VisitSequencesInSep (sep, NULL, VISIT_PARTS, RemoveLocusProc);
14526   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14527   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14528 }
14529 
14530 typedef struct gosstruc {
14531   CharPtr       term;
14532   Char          goid [32];
14533   CharPtr       evidence;
14534   Int4          pmid;
14535   UserFieldPtr  ufp;
14536 } GosStruc, PNTR GosStrucPtr;
14537 
SortVnpByGssp(VoidPtr ptr1,VoidPtr ptr2)14538 static int LIBCALLBACK SortVnpByGssp (VoidPtr ptr1, VoidPtr ptr2)
14539 
14540 {
14541   int           compare;
14542   GosStrucPtr   gsp1, gsp2;
14543   ValNodePtr    vnp1, vnp2;
14544 
14545   if (ptr1 == NULL || ptr2 == NULL) return 0;
14546   vnp1 = *((ValNodePtr PNTR) ptr1);
14547   vnp2 = *((ValNodePtr PNTR) ptr2);
14548   if (vnp1 == NULL || vnp2 == NULL) return 0;
14549   gsp1 = (GosStrucPtr) vnp1->data.ptrvalue;
14550   gsp2 = (GosStrucPtr) vnp2->data.ptrvalue;
14551   if (gsp1 == NULL || gsp2 == NULL) return 0;
14552 
14553   compare = StringICmp (gsp1->goid, gsp2->goid);
14554   if (compare > 0) {
14555     return 1;
14556   } else if (compare < 0) {
14557     return -1;
14558   }
14559 
14560   compare = StringICmp (gsp1->term, gsp2->term);
14561   if (compare > 0) {
14562     return 1;
14563   } else if (compare < 0) {
14564     return -1;
14565   }
14566 
14567   compare = StringICmp (gsp1->evidence, gsp2->evidence);
14568   if (compare > 0) {
14569     return 1;
14570   } else if (compare < 0) {
14571     return -1;
14572   }
14573 
14574   if (gsp1->pmid == 0) return 1;
14575   if (gsp2->pmid == 0) return -1;
14576   if (gsp1->pmid > gsp2->pmid) {
14577     return 1;
14578   } else if (gsp1->pmid < gsp2->pmid) {
14579     return -1;
14580   }
14581 
14582   return 0;
14583 }
14584 
SortGoTerms(UserFieldPtr entryhead)14585 static UserFieldPtr SortGoTerms (
14586   UserFieldPtr entryhead
14587 )
14588 
14589 {
14590   UserFieldPtr  entry, topufp, ufp, lastufp;
14591   CharPtr       evidence, goid, textstr;
14592   Char          gid [32];
14593   GosStrucPtr   gsp, lastgsp;
14594   ValNodePtr    head = NULL, vnp;
14595   Int2          j;
14596   ObjectIdPtr   oip;
14597   Int4          pmid;
14598 
14599   if (entryhead == NULL) return entryhead;
14600 
14601   for (entry = entryhead; entry != NULL; entry = entry->next) {
14602     if (entry == NULL || entry->choice != 11) break;
14603     topufp = (UserFieldPtr)  entry->data.ptrvalue;
14604     if (topufp == NULL) continue;
14605 
14606     textstr = NULL;
14607     evidence = NULL;
14608     goid = NULL;
14609     pmid = 0;
14610     for (ufp = topufp; ufp != NULL; ufp = ufp->next) {
14611       oip = ufp->label;
14612       if (oip == NULL) continue;
14613       for (j = 0; goFieldType [j] != NULL; j++) {
14614         if (StringICmp (oip->str, goFieldType [j]) == 0) break;
14615       }
14616       if (goFieldType [j] == NULL) continue;
14617       switch (j) {
14618         case 1 :
14619           if (ufp->choice == 1) {
14620             textstr = (CharPtr) ufp->data.ptrvalue;
14621           }
14622           break;
14623         case 2 :
14624           if (ufp->choice == 1) {
14625             goid = (CharPtr) ufp->data.ptrvalue;
14626           } else if (ufp->choice == 2) {
14627             sprintf (gid, "%ld", (long) (Int4) ufp->data.intvalue);
14628             goid = (CharPtr) gid;
14629           }
14630           break;
14631         case 3 :
14632           if (ufp->choice == 2) {
14633             pmid = (Int4) ufp->data.intvalue;
14634           }
14635           break;
14636         case 4 :
14637           if (ufp->choice == 1) {
14638             evidence = (CharPtr) ufp->data.ptrvalue;
14639           }
14640           break;
14641         default :
14642           break;
14643       }
14644     }
14645 
14646     if (StringDoesHaveText (textstr)) {
14647       gsp = (GosStrucPtr) MemNew (sizeof (GosStruc));
14648       if (gsp != NULL) {
14649         gsp->term = textstr;
14650         StringNCpy_0 (gsp->goid, goid, sizeof (gsp->goid));
14651         gsp->evidence = evidence;
14652         gsp->pmid = pmid;
14653         gsp->ufp = entry;
14654         ValNodeAddPointer (&head, 0, (Pointer) gsp);
14655       }
14656     }
14657   }
14658 
14659   if (head == NULL) return entryhead;
14660   head = ValNodeSort (head, SortVnpByGssp);
14661 
14662   entryhead = NULL;
14663   lastgsp = NULL;
14664   lastufp = NULL;
14665   for (vnp = head; vnp != NULL; vnp = vnp->next) {
14666     gsp = (GosStrucPtr) vnp->data.ptrvalue;
14667     if (gsp == NULL || gsp->ufp == NULL) continue;
14668     if (lastgsp != NULL &&
14669         (StringICmp (gsp->term, lastgsp->term) == 0 || StringICmp (gsp->goid, lastgsp->goid) == 0) &&
14670         (gsp->pmid == lastgsp->pmid && StringICmp (gsp->evidence, lastgsp->evidence) == 0)) {
14671       gsp->ufp->next = NULL;
14672       UserFieldFree (gsp->ufp);
14673     } else {
14674       if (lastufp != NULL) {
14675         lastufp->next = gsp->ufp;
14676       } else {
14677         entryhead = gsp->ufp;
14678       }
14679       lastufp = gsp->ufp;
14680       lastufp->next = NULL;
14681     }
14682     lastgsp = gsp;
14683   }
14684 
14685   ValNodeFreeData (head);
14686 
14687   return entryhead;
14688 }
14689 
SortGoTermsUfp(UserFieldPtr ufp,Pointer userdata)14690 static void SortGoTermsUfp (
14691   UserFieldPtr ufp,
14692   Pointer userdata
14693 )
14694 
14695 {
14696   UserFieldPtr  entry;
14697   Int2          i;
14698   ObjectIdPtr   oip;
14699 
14700   if (ufp == NULL || ufp->choice != 11) return;
14701   oip = ufp->label;
14702   if (oip == NULL) return;
14703   for (i = 0; goQualType [i] != NULL; i++) {
14704     if (StringICmp (oip->str, goQualType [i]) == 0) break;
14705   }
14706   if (goQualType [i] == NULL) return;
14707 
14708   entry = ufp->data.ptrvalue;
14709   if (entry == NULL || entry->choice != 11) return;
14710 
14711   ufp->data.ptrvalue = SortGoTerms (entry);
14712 }
14713 
SortGoTermsSfp(UserObjectPtr uop,Pointer userdata)14714 static void SortGoTermsSfp (
14715   UserObjectPtr uop,
14716   Pointer userdata
14717 )
14718 
14719 {
14720   ObjectIdPtr  oip;
14721 
14722   if (uop == NULL) return;
14723   oip = uop->type;
14724   if (oip == NULL) return;
14725   if (StringCmp (oip->str, "GeneOntology") == 0) {
14726     VisitUserFieldsInUop (uop, userdata, SortGoTermsUfp);
14727   }
14728 }
14729 
LookForGoTerms(SeqFeatPtr sfp,Pointer userdata)14730 static void LookForGoTerms (SeqFeatPtr sfp, Pointer userdata)
14731 
14732 {
14733   if (sfp != NULL && sfp->ext != NULL) {
14734     VisitUserObjectsInUop (sfp->ext, NULL, SortGoTermsSfp);
14735   }
14736 }
14737 
RemoveDuplicateGeneOntology(IteM i)14738 static void RemoveDuplicateGeneOntology (IteM i)
14739 
14740 {
14741   BaseFormPtr  bfp;
14742   SeqEntryPtr  sep;
14743 
14744 #ifdef WIN_MAC
14745   bfp = currentFormDataPtr;
14746 #else
14747   bfp = GetObjectExtra (i);
14748 #endif
14749   if (bfp == NULL) return;
14750   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14751   if (sep == NULL) return;
14752   VisitFeaturesInSep (sep, NULL, LookForGoTerms);
14753   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14754   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14755 }
14756 
14757 
RemoveDuplicateStructuredComments(IteM i)14758 static void RemoveDuplicateStructuredComments (IteM i)
14759 {
14760   BaseFormPtr  bfp;
14761   SeqEntryPtr  sep;
14762 
14763 #ifdef WIN_MAC
14764   bfp = currentFormDataPtr;
14765 #else
14766   bfp = GetObjectExtra (i);
14767 #endif
14768   if (bfp == NULL) return;
14769   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14770   if (sep == NULL) return;
14771 
14772   RemoveDuplicateStructuredCommentsInSeqEntry (sep);
14773   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14774   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14775 }
14776 
14777 
RemoveEmptyStructuredCommentsItem(IteM i)14778 static void RemoveEmptyStructuredCommentsItem (IteM i)
14779 {
14780   BaseFormPtr  bfp;
14781 
14782 #ifdef WIN_MAC
14783   bfp = currentFormDataPtr;
14784 #else
14785   bfp = GetObjectExtra (i);
14786 #endif
14787   if (bfp == NULL) return;
14788 
14789   RemoveEmptyStructuredComments (bfp->input_entityID);
14790   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14791   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14792 }
14793 
14794 
RemoveAssemblyProc(BioseqPtr bsp,Pointer userdata)14795 static void RemoveAssemblyProc (BioseqPtr bsp, Pointer userdata)
14796 
14797 {
14798   SeqHistPtr  hist;
14799 
14800   hist = bsp->hist;
14801   if (hist == NULL) return;
14802   hist->assembly = SeqAlignFree (hist->assembly);
14803   if (hist->assembly != NULL || hist->replace_date != NULL ||
14804       hist->replace_ids != NULL || hist->replaced_by_date != NULL ||
14805       hist->replaced_by_ids != NULL || hist->deleted_date != NULL) return;
14806   bsp->hist = SeqHistFree (bsp->hist);
14807 }
14808 
RemoveSeqHistAssembly(IteM i)14809 static void RemoveSeqHistAssembly (IteM i)
14810 
14811 {
14812   BaseFormPtr  bfp;
14813   SeqEntryPtr  sep;
14814 
14815 #ifdef WIN_MAC
14816   bfp = currentFormDataPtr;
14817 #else
14818   bfp = GetObjectExtra (i);
14819 #endif
14820   if (bfp == NULL) return;
14821   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
14822   if (sep == NULL) return;
14823   VisitBioseqsInSep (sep, NULL, RemoveAssemblyProc);
14824   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
14825   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
14826 }
14827 
14828 
14829 typedef struct streamfsa {
14830   FILE  *fp;
14831   Char  buf [128];
14832   Int2  idx;
14833   Int2  maxlen;
14834 } StreamFsa, PNTR StreamFsaPtr;
14835 
FsaStreamProc(CharPtr sequence,Pointer userdata)14836 static void LIBCALLBACK FsaStreamProc (
14837   CharPtr sequence,
14838   Pointer userdata
14839 )
14840 
14841 {
14842   Char          ch;
14843   StreamFsaPtr  sfp;
14844 
14845   if (StringHasNoText (sequence) || userdata == NULL) return;
14846   sfp = (StreamFsaPtr) userdata;
14847 
14848   ch = *sequence;
14849   while (ch != '\0') {
14850     sfp->buf [sfp->idx] = ch;
14851     (sfp->idx)++;
14852 
14853     if (sfp->idx >= sfp->maxlen) {
14854       sfp->buf [sfp->idx] = '\0';
14855       fprintf (sfp->fp, "%s\n", sfp->buf);
14856       sfp->idx = 0;
14857     }
14858 
14859     sequence++;
14860     ch = *sequence;
14861   }
14862 }
14863 
14864 
14865 typedef struct recondata {
14866   BioseqPtr   prod;
14867   SeqFeatPtr  cds;
14868   SeqFeatPtr  prt;
14869   Boolean     notunique;
14870 } ReconData, PNTR ReconDataPtr;
14871 
GetReconFunc(GatherContextPtr gcp)14872 static Boolean GetReconFunc (GatherContextPtr gcp)
14873 
14874 {
14875   BioseqPtr     bsp;
14876   ReconDataPtr  rdp;
14877   SeqFeatPtr    sfp;
14878 
14879   if (gcp == NULL || gcp->thisitem == NULL) return TRUE;
14880   rdp = (ReconDataPtr) gcp->userdata;
14881   if (rdp == NULL) return TRUE;
14882   switch (gcp->thistype) {
14883     case OBJ_SEQFEAT :
14884       sfp = (SeqFeatPtr) gcp->thisitem;
14885       if (sfp->data.choice == SEQFEAT_CDREGION) {
14886         if (rdp->cds != NULL) {
14887           rdp->notunique = TRUE;
14888         } else {
14889           rdp->cds = sfp;
14890         }
14891       } else if (sfp->data.choice == SEQFEAT_PROT) {
14892         if (rdp->prt == NULL) {
14893           rdp->prt = sfp; /* gets first protein, not largest, since location wrong */
14894         }
14895       }
14896       break;
14897     case OBJ_BIOSEQ :
14898       bsp = (BioseqPtr) gcp->thisitem;
14899       if (ISA_aa (bsp->mol)) {
14900         if (rdp->prod != NULL) {
14901           rdp->notunique = TRUE;
14902         } else {
14903           rdp->prod = bsp;
14904         }
14905       }
14906       break;
14907     default :
14908       break;
14909   }
14910   if (gcp->thistype != OBJ_SEQFEAT) return TRUE;
14911   return TRUE;
14912 }
14913 
ReconnectCDSProc(Uint2 entityID,SeqEntryPtr sep)14914 static void ReconnectCDSProc (Uint2 entityID, SeqEntryPtr sep)
14915 
14916 {
14917   BioseqSetPtr  bssp;
14918   GatherScope   gs;
14919   MolInfoPtr    mip;
14920   Boolean       partial5;
14921   Boolean       partial3;
14922   ReconData     rd;
14923   SeqLocPtr     slp;
14924   ValNodePtr    vnp;
14925 
14926   if (sep == NULL) return;
14927   if (IS_Bioseq_set (sep)) {
14928     bssp = (BioseqSetPtr) sep->data.ptrvalue;
14929     if (bssp != NULL && (bssp->_class == 7 ||
14930                          (IsPopPhyEtcSet (bssp->_class)))) {
14931       for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
14932         ReconnectCDSProc (entityID, sep);
14933       }
14934       return;
14935     }
14936   }
14937 
14938   MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
14939   gs.seglevels = 1;
14940   gs.get_feats_location = FALSE;
14941   MemSet ((Pointer) (gs.ignore), (int)(TRUE), (size_t) (OBJ_MAX * sizeof(Boolean)));
14942   gs.ignore[OBJ_BIOSEQ] = FALSE;
14943   gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
14944   gs.ignore[OBJ_SEQANNOT] = FALSE;
14945   gs.ignore[OBJ_SEQFEAT] = FALSE;
14946   gs.scope = sep;
14947   rd.prod = NULL;
14948   rd.cds = NULL;
14949   rd.prt = NULL;
14950   rd.notunique = FALSE;
14951   partial5 = FALSE;
14952   partial3 = FALSE;
14953   GatherEntity (entityID, (Pointer) (&rd), GetReconFunc, &gs);
14954   if (rd.notunique) return;
14955   if (rd.prod != NULL && rd.cds != NULL) {
14956     slp = SeqLocFindNext (rd.cds->location, NULL);
14957     if (slp != NULL) {
14958       CheckSeqLocForPartial (slp, &partial5, &partial3);
14959     }
14960     sep = SeqMgrGetSeqEntryForData (rd.prod);
14961     if (sep != NULL) {
14962       SetSeqFeatProduct (rd.cds, rd.prod);
14963       if (rd.prt != NULL) {
14964         rd.prt->location = SeqLocFree (rd.prt->location);
14965         rd.prt->location = CreateWholeInterval (sep);
14966         SetSeqLocPartial (rd.prt->location, partial5, partial3);
14967         rd.prt->partial = (partial5 || partial3);
14968         vnp = SeqEntryGetSeqDescr (sep, Seq_descr_molinfo, NULL);
14969         if (vnp == NULL) {
14970           vnp = CreateNewDescriptor (sep, Seq_descr_molinfo);
14971           if (vnp != NULL) {
14972             mip = MolInfoNew ();
14973             vnp->data.ptrvalue = (Pointer) mip;
14974             if (mip != NULL) {
14975               mip->biomol = 8;
14976               mip->tech = 13;
14977             }
14978           }
14979         }
14980         if (vnp != NULL) {
14981           mip = (MolInfoPtr) vnp->data.ptrvalue;
14982           if (mip != NULL) {
14983             if (partial5 && partial3) {
14984               mip->completeness = 5;
14985             } else if (partial5) {
14986               mip->completeness = 3;
14987             } else if (partial3) {
14988               mip->completeness = 4;
14989             /*
14990             } else if (partial) {
14991               mip->completeness = 2;
14992             */
14993             } else {
14994               mip->completeness = 0;
14995             }
14996           }
14997         }
14998       }
14999     }
15000   }
15001 }
15002 
ReconnectCDSProduct(IteM i)15003 static void ReconnectCDSProduct (IteM i)
15004 
15005 {
15006   BaseFormPtr  bfp;
15007   SeqEntryPtr  sep;
15008 
15009 #ifdef WIN_MAC
15010   bfp = currentFormDataPtr;
15011 #else
15012   bfp = GetObjectExtra (i);
15013 #endif
15014   if (bfp == NULL) return;
15015   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
15016   if (sep == NULL) return;
15017   ReconnectCDSProc (bfp->input_entityID, sep);
15018   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
15019   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
15020 }
15021 
15022 
AtccToCultureCollectionBaseForm(BaseFormPtr bfp)15023 static void AtccToCultureCollectionBaseForm (BaseFormPtr bfp)
15024 {
15025   SeqEntryPtr  sep;
15026   ValNodePtr   object_list = NULL, vnp;
15027   AECRSamplePtr       sample;
15028   SourceQualPairPtr   pair;
15029   SourceQualChoicePtr scp;
15030   ValNodePtr          field_from, field_to;
15031   AECRParseActionPtr  parse;
15032   AECRActionPtr       action;
15033   CharPtr             str1, str2, cp, new_str;
15034   Uint2               from_fields[] = { Source_qual_strain, Source_qual_cell_line, Source_qual_tissue_type };
15035   Int4                num_from = 3, i;
15036   SourceConstraintPtr src_const;
15037 
15038   if (bfp == NULL) return;
15039   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
15040   if (sep == NULL) return;
15041 
15042   parse = AECRParseActionNew ();
15043 
15044   parse->fields = ValNodeNew (NULL);
15045   parse->fields->choice = FieldPairType_source_qual;
15046   pair = SourceQualPairNew ();
15047   pair->field_from = Source_qual_strain;
15048   pair->field_to = Source_qual_culture_collection;
15049   parse->fields->data.ptrvalue = pair;
15050 
15051   parse->portion = TextPortionNew ();
15052   parse->portion->left_marker = MakeTextTextMarker ("ATCC");
15053   parse->portion->include_left = FALSE;
15054   parse->portion->right_marker = NULL;
15055   parse->portion->include_right = FALSE;
15056   parse->portion->inside = TRUE;
15057   parse->portion->case_sensitive = FALSE;
15058   parse->portion->whole_word = FALSE;
15059 
15060   parse->remove_from_parsed = FALSE;
15061   parse->remove_left = FALSE;
15062   parse->remove_right = FALSE;
15063   parse->existing_text = ExistingTextOption_add_qual;
15064 
15065   action = AECRActionNew ();
15066   action->action = ValNodeNew (NULL);
15067   action->action->choice = ActionChoice_parse;
15068   action->action->data.ptrvalue = parse;
15069   src_const = SourceConstraintNew();
15070   src_const->field1 = ValNodeNew (NULL);
15071   src_const->field1->choice = SourceQualChoice_textqual;
15072   src_const->field1->data.intvalue = Source_qual_strain;
15073   src_const->constraint = StringConstraintNew ();
15074   src_const->constraint->match_text = StringSave("ATCC");
15075   src_const->constraint->match_location = String_location_equals;
15076   src_const->constraint->not_present = TRUE;
15077   action->constraint = ValNodeNew (NULL);
15078   action->constraint->choice = ConstraintChoice_source;
15079   action->constraint->data.ptrvalue = src_const;
15080 
15081   for (i = 0; i < num_from; i++) {
15082     pair->field_from = from_fields[i];
15083     ValNodeLink (&object_list, GetObjectListForAECRAction (sep, action));
15084   }
15085 
15086   field_to = GetToFieldFromFieldPair (parse->fields);
15087 
15088   sample = GetAECRSampleFromObjectList (object_list, field_to);
15089   if (sample != NULL && sample->num_found > 0) {
15090     parse->existing_text = TwoStepExistingText (sample->num_found, FALSE, TRUE);
15091   }
15092   sample = AECRSampleFree (sample);
15093   if (parse->existing_text != 0) {
15094     WatchCursor ();
15095     Update ();
15096     field_from = GetFromFieldFromFieldPair (parse->fields);
15097     scp = (SourceQualChoicePtr) field_from->data.ptrvalue;
15098     for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
15099       str2 = NULL;
15100       for (i = 0; i < num_from && str2 == NULL; i++) {
15101         scp->data.intvalue = from_fields[i];
15102         str1 = GetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_from, NULL);
15103         str2 = GetTextPortionFromString (str1, parse->portion);
15104         str1 = MemFree (str1);
15105       }
15106       if (str2 != NULL) {
15107         cp = StringChr (str2, ';');
15108         if (cp != NULL) {
15109           *cp = 0;
15110         }
15111         /* advance marker past spaces */
15112         cp = str2;
15113         while (isspace (*cp)) {
15114           cp++;
15115         }
15116         new_str = (CharPtr) MemNew (sizeof (Char) * (5 + StringLen (cp) + 1));
15117         sprintf (new_str, "ATCC:%s", cp);
15118         SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_to, NULL, new_str, parse->existing_text);
15119         new_str = MemFree (new_str);
15120       }
15121       str2 = MemFree (str2);
15122     }
15123     field_from = FieldTypeFree (field_from);
15124     ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
15125     ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
15126     ArrowCursor ();
15127     Update ();
15128   }
15129   field_to = FieldTypeFree (field_to);
15130   object_list = FreeObjectList (object_list);
15131   action = AECRActionFree (action);
15132 }
15133 
15134 
AtccToCultureCollection(IteM i)15135 static void AtccToCultureCollection (IteM i)
15136 {
15137   BaseFormPtr  bfp;
15138 
15139 #ifdef WIN_MAC
15140   bfp = currentFormDataPtr;
15141 #else
15142   bfp = GetObjectExtra (i);
15143 #endif
15144 
15145   AtccToCultureCollectionBaseForm (bfp);
15146 }
15147 
15148 
15149 typedef struct extendgeneformglobalitemdata {
15150   Int4		iFeatDef;
15151   Boolean	item_value;
15152   Boolean	upstream;
15153   CharPtr	label;
15154 } ExtendGeneFormGlobalItemData, PNTR ExtendGeneFormGlobalItemPtr;
15155 
15156 typedef struct extendgeneformlocalitemdata {
15157   ButtoN	item_button;
15158   Boolean	item_value;
15159   SeqFeatPtr	plus_sfp;
15160   SeqFeatPtr	minus_sfp;
15161 } ExtendGeneFormLocalItemData, PNTR ExtendGeneFormLocalItemPtr;
15162 
15163 static ExtendGeneFormGlobalItemData list_of_regulatory_items[] = {
15164 	{ FEATDEF_attenuator, FALSE, FALSE, "attenuator" },
15165 	{ FEATDEF_attenuator, FALSE, TRUE, "attenuator" },
15166 	{ FEATDEF_CAAT_signal, FALSE, TRUE, "CAAT signal" },
15167 	{ FEATDEF_enhancer, FALSE, TRUE, "enhancer" },
15168 	{ FEATDEF_GC_signal, FALSE, TRUE, "GC signal" },
15169 	{ FEATDEF_misc_binding, FALSE, TRUE, "misc binding" },
15170 	{ FEATDEF_misc_feature, FALSE, TRUE, "misc feature" },
15171 	{ FEATDEF_misc_signal, FALSE, TRUE, "misc signal" },
15172 	{ FEATDEF_misc_structure, FALSE, TRUE, "misc structure" },
15173 	{ FEATDEF_promoter, FALSE, TRUE, "promoter" },
15174 	{ FEATDEF_protein_bind, FALSE, TRUE, "protein bind" },
15175 	{ FEATDEF_RBS, TRUE, TRUE, "RBS" },
15176 	{ FEATDEF_stem_loop, FALSE, TRUE, "stem loop" },
15177 	{ FEATDEF_TATA_signal, FALSE, TRUE, "TATA signal" },
15178 	{ FEATDEF_terminator, FALSE, FALSE, "terminator" },
15179 	{ FEATDEF_5UTR, TRUE, TRUE, "5'UTR" },
15180 	{ FEATDEF_3UTR, TRUE, FALSE, "3'UTR" },
15181 	{ FEATDEF_10_signal, FALSE, TRUE, "-10 signal" },
15182 	{ FEATDEF_35_signal, FALSE, TRUE, "-35 signal" },
15183 };
15184 
15185 const Int4 NUM_REGULATORY_ITEMS =
15186 	sizeof(list_of_regulatory_items) / sizeof(ExtendGeneFormGlobalItemData);
15187 
15188 typedef struct extendgeneformdata {
15189   FEATURE_FORM_BLOCK
15190 
15191   ButtoN	PlusStrand;
15192   ButtoN	MinusStrand;
15193   Boolean	doPlusStrand;
15194   Boolean	doMinusStrand;
15195   ButtoN	ResetGenes;
15196   ButtoN	StealFeatures;
15197   Boolean	doResetGenes;
15198   Boolean	doStealFeatures;
15199   ButtoN	LogEvents;
15200   ButtoN	LogUnextendedEvents;
15201   Boolean	doLogEvents;
15202   Boolean	doLogUnextendedEvents;
15203   ExtendGeneFormLocalItemPtr	item_list;
15204   FILE		*fp;
15205 } ExtendGeneFormData, PNTR ExtendGeneFormPtr;
15206 
GetGeneName(GeneRefPtr grp)15207 static CharPtr GetGeneName(GeneRefPtr grp)
15208 {
15209   if (!HasNoText (grp->locus)) return grp->locus;
15210   if (!HasNoText (grp->locus_tag)) return grp->locus_tag;
15211   if (!HasNoText (grp->desc)) return grp->desc;
15212   return NULL;
15213 }
15214 
LogLocation(SeqMgrFeatContextPtr context,FILE * fp)15215 static void LogLocation (SeqMgrFeatContextPtr context, FILE *fp)
15216 {
15217   if (context->strand == Seq_strand_minus)
15218   {
15219     fprintf (fp, "at complement(%d..%d)", context->left, context->right);
15220   }
15221   else
15222   {
15223     fprintf (fp, "at %d..%d", context->left, context->right);
15224   }
15225 }
15226 
15227 typedef struct correctgeneformdata {
15228   FEATURE_FORM_BLOCK
15229 
15230   ButtoN      setIntervalBtn;
15231   ButtoN      setStrandBtn;
15232   ButtoN      logChangesBtn;
15233   ButtoN      correct_selected_pair;
15234   DialoG      constraint_dlg;
15235   GrouP       feature_choice_grp;
15236   Uint1       featdeftype;
15237   Boolean     setInterval;
15238   Boolean     setStrand;
15239   ValNodePtr  constraint;
15240   SeqEntryPtr sep;
15241   FILE *      fp;
15242 } CorrectGeneFormData, PNTR CorrectGeneFormPtr;
15243 
15244 typedef struct genesforcdsdata {
15245   SeqLocPtr      test_loc;
15246   ValNodePtr     gene_list;
15247   Boolean        same_strand_only;
15248 } GenesForCDSData, PNTR GenesForCDSPtr;
15249 
FindGenesForCDS(SeqFeatPtr sfp,Pointer userdata)15250 static void FindGenesForCDS (SeqFeatPtr sfp, Pointer userdata)
15251 {
15252   GenesForCDSPtr gfc;
15253   ValNodePtr     vnp;
15254   Uint1          strand_cds, strand_gene;
15255 
15256   gfc = (GenesForCDSPtr) userdata;
15257 
15258   if (gfc == NULL || sfp == NULL || sfp->idx.subtype != FEATDEF_GENE)
15259   {
15260     return;
15261   }
15262 
15263   /* unless we plan to correct to same strand, only look at locations on same strand */
15264   if (gfc->same_strand_only)
15265   {
15266     strand_cds = SeqLocStrand (gfc->test_loc);
15267     strand_gene = SeqLocStrand (sfp->location);
15268     if (strand_cds == Seq_strand_minus && strand_gene != Seq_strand_minus)
15269     {
15270       return;
15271     }
15272     else if (strand_cds != Seq_strand_minus && strand_gene == Seq_strand_minus)
15273     {
15274       return;
15275     }
15276   }
15277 
15278   if (SeqLocAinB (gfc->test_loc, sfp->location) > -1
15279     || SeqLocAinB (sfp->location, gfc->test_loc) > -1)
15280   {
15281     vnp = ValNodeNew (gfc->gene_list);
15282     if (vnp == NULL) return;
15283     vnp->data.ptrvalue = sfp;
15284     if (gfc->gene_list == NULL)
15285     {
15286       gfc->gene_list = vnp;
15287     }
15288   }
15289 }
15290 
SetSeqLocStrand(SeqLocPtr location,Uint1 strand)15291 extern void SetSeqLocStrand (SeqLocPtr location, Uint1 strand)
15292 {
15293   SeqLocPtr slp;
15294   SeqIntPtr sip;
15295   SeqPntPtr spp;
15296 
15297   slp = SeqLocFindNext (location, NULL);
15298   while (slp != NULL)
15299   {
15300     if (slp == NULL || slp->data.ptrvalue == NULL)
15301     {
15302       slp = SeqLocFindNext (location, slp);
15303       continue;
15304     }
15305     if (slp->choice == SEQLOC_INT)
15306     {
15307       sip = (SeqIntPtr)slp->data.ptrvalue;
15308       sip->strand = strand;
15309     }
15310     else if (slp->choice == SEQLOC_PNT)
15311     {
15312       spp = (SeqPntPtr)slp->data.ptrvalue;
15313       spp->strand = strand;
15314     }
15315     slp = SeqLocFindNext (location, slp);
15316   }
15317 }
15318 
15319 static void
CorrectOneCDSGenePair(SeqFeatPtr cds,SeqFeatPtr gene,BioseqPtr bsp,CorrectGeneFormPtr cgp)15320 CorrectOneCDSGenePair
15321 (SeqFeatPtr cds, SeqFeatPtr gene, BioseqPtr bsp, CorrectGeneFormPtr cgp)
15322 {
15323   Boolean   need_change;
15324   SeqLocPtr slp;
15325   Boolean   oldpartial5, oldpartial3, partial5, partial3;
15326   CharPtr   cds_label;
15327   CharPtr            genename = NULL;
15328   SeqMgrFeatContext  fcontext;
15329   Uint1              strand_cds, strand_gene;
15330   Char               id_txt [128];
15331 
15332   if (cds == NULL || gene == NULL || cgp == NULL)
15333   {
15334     return;
15335   }
15336 
15337   if (bsp == NULL)
15338   {
15339     bsp = BioseqFindFromSeqLoc (cds->location);
15340     if (bsp == NULL)
15341     {
15342       return;
15343     }
15344   }
15345 
15346   if (cgp->setInterval)
15347   {
15348     need_change = FALSE;
15349     slp = SeqLocMerge (bsp, cds->location, NULL, TRUE, TRUE, FALSE);
15350     if (SeqLocCompare (slp, gene->location) != SLC_A_EQ_B)
15351     {
15352       need_change = TRUE;
15353     }
15354     CheckSeqLocForPartial (gene->location, &oldpartial5, &oldpartial3);
15355     CheckSeqLocForPartial (cds->location, &partial5, &partial3);
15356     if (oldpartial5 != partial5 || oldpartial3 != partial3)
15357     {
15358       need_change = TRUE;
15359     }
15360     if (need_change)
15361     {
15362       SetSeqLocPartial (slp, partial5, partial3);
15363       SeqLocFree (gene->location);
15364       gene->location = slp;
15365       gene->partial = partial5 || partial3;
15366       if (cgp->fp != NULL)
15367       {
15368         SeqIdWrite (SeqIdFindBest (bsp->id, SEQID_GENBANK), id_txt, PRINTID_REPORT, sizeof (id_txt) - 1);
15369         if (!StringHasNoText (id_txt))
15370         {
15371           fprintf (cgp->fp, "Sequence %s: ", id_txt);
15372         }
15373         genename = GetGeneName ((GeneRefPtr) gene->data.value.ptrvalue);
15374         cds = SeqMgrGetDesiredFeature (cds->idx.entityID, NULL, 0, 0, cds, &fcontext);
15375         if (genename == NULL)
15376         {
15377           fprintf (cgp->fp, "Unnamed gene ");
15378           LogLocation (&fcontext, cgp->fp);
15379         }
15380         else
15381         {
15382           fprintf (cgp->fp, "Gene %s", genename);
15383         }
15384         cds_label = StringSave (fcontext.label);
15385         if (StringLen (cds_label) > 20)
15386         {
15387           cds_label[20] = 0;
15388         }
15389         fprintf (cgp->fp, " reset to %s interval (%s)\n", cgp->featdeftype == FEATDEF_CDS ? "CDS" : "mRNA", cds_label);
15390         cds_label = MemFree (cds_label);
15391       }
15392     }
15393     else
15394     {
15395       SeqLocFree (slp);
15396     }
15397   }
15398   if (cgp->setStrand)
15399   {
15400     need_change = FALSE;
15401     strand_cds = SeqLocStrand (cds->location);
15402     strand_gene = SeqLocStrand (gene->location);
15403     if (strand_cds == Seq_strand_minus && strand_gene != Seq_strand_minus)
15404     {
15405       need_change = TRUE;
15406     }
15407     else if (strand_cds != Seq_strand_minus && strand_gene == Seq_strand_minus)
15408     {
15409       need_change = TRUE;
15410     }
15411     if (need_change)
15412     {
15413       SetSeqLocStrand (gene->location, strand_cds);
15414       if (cgp->fp != NULL)
15415       {
15416         cds = SeqMgrGetDesiredFeature (cds->idx.entityID, NULL, 0, 0, cds, &fcontext);
15417         genename = GetGeneName ((GeneRefPtr) gene->data.value.ptrvalue);
15418         if (genename == NULL)
15419         {
15420           fprintf (cgp->fp, "Unnamed gene ");
15421           LogLocation (&fcontext, cgp->fp);
15422         }
15423         else
15424         {
15425           fprintf (cgp->fp, "Gene %s", genename);
15426         }
15427         cds_label = StringSave (fcontext.label);
15428         if (StringLen (cds_label) > 20)
15429         {
15430           cds_label[20] = 0;
15431         }
15432         fprintf (cgp->fp, " strand set to match CDS (%s)\n", cds_label);
15433         cds_label = MemFree (cds_label);
15434       }
15435     }
15436   }
15437 }
15438 
15439 
ReduceGeneList(SeqFeatPtr sfp,ValNodePtr PNTR gene_list)15440 static void ReduceGeneList (SeqFeatPtr sfp, ValNodePtr PNTR gene_list)
15441 {
15442   SeqFeatPtr gene;
15443   Boolean match_found = FALSE, extra_found = FALSE;
15444   ValNodePtr vnp, extract;
15445 
15446   if (sfp == NULL || gene_list == NULL || *gene_list == NULL || (*gene_list)->next == NULL) {
15447     return;
15448   }
15449 
15450   for (vnp = *gene_list; vnp != NULL && !extra_found; vnp = vnp->next) {
15451     gene = (SeqFeatPtr) vnp->data.ptrvalue;
15452     if (SeqLocCompare (gene->location, sfp->location) == SLC_A_EQ_B) {
15453       if (match_found) {
15454         extra_found = TRUE;
15455       } else {
15456         match_found = TRUE;
15457         vnp->choice = 1;
15458       }
15459     }
15460   }
15461   if (!match_found) {
15462     /* if we didn't find an exact match, is there only one with the right endpoints?
15463      */
15464     for (vnp = *gene_list; vnp != NULL && !extra_found; vnp = vnp->next) {
15465       gene = (SeqFeatPtr) vnp->data.ptrvalue;
15466       if (SeqLocCompare (gene->location, sfp->location) == SLC_A_OVERLAP_B
15467           && SeqLocStart (gene->location) == SeqLocStart (sfp->location)
15468           && SeqLocStop (gene->location) == SeqLocStop (sfp->location)) {
15469         if (match_found) {
15470           extra_found = TRUE;
15471         } else {
15472           match_found = TRUE;
15473           vnp->choice = 1;
15474         }
15475       }
15476     }
15477   }
15478   if (match_found && !extra_found) {
15479     extract = ValNodeExtractList (gene_list, 0);
15480     extract = ValNodeFree (extract);
15481   }
15482 }
15483 
15484 
CorrectOneCDSGene(SeqFeatPtr sfp,Pointer userdata)15485 static void CorrectOneCDSGene (SeqFeatPtr sfp, Pointer userdata)
15486 {
15487   CorrectGeneFormPtr cgp;
15488   GenesForCDSData    gfc;
15489   SeqFeatPtr         gene;
15490   SeqFeatXrefPtr     gene_xref;
15491   GeneRefPtr         grp;
15492   SeqMgrFeatContext  fcontext;
15493   CharPtr            cds_label;
15494   BioseqPtr          bsp;
15495 
15496   if (sfp == NULL
15497       || (cgp = (CorrectGeneFormPtr)userdata) == NULL
15498       || sfp->idx.subtype != cgp->featdeftype)
15499   {
15500     return;
15501   }
15502 
15503   if (!DoesObjectMatchConstraintChoiceSet (OBJ_SEQFEAT, sfp, cgp->constraint))
15504   {
15505     return;
15506   }
15507 
15508   bsp = BioseqFindFromSeqLoc (sfp->location);
15509   gfc.test_loc = SeqLocMerge (bsp, sfp->location, NULL, TRUE, TRUE, FALSE);
15510 
15511   gfc.gene_list = NULL;
15512   gfc.same_strand_only = ! cgp->setStrand;
15513 
15514   gene_xref = sfp->xref;
15515   while (gene_xref != NULL)
15516   {
15517     if (gene_xref->data.choice == SEQFEAT_GENE && gene_xref->data.value.ptrvalue != NULL)
15518     {
15519       grp = (GeneRefPtr) gene_xref->data.value.ptrvalue;
15520       if (!StringHasNoText (grp->locus))
15521       {
15522         gene = SeqMgrGetFeatureByLabel (bsp, grp->locus, SEQFEAT_GENE, 0, &fcontext);
15523         if (gene != NULL)
15524         {
15525           ValNodeAddPointer (&(gfc.gene_list), 0, gene);
15526         }
15527       }
15528     }
15529     gene_xref = gene_xref->next;
15530   }
15531 
15532   if (gfc.gene_list == NULL)
15533   {
15534     VisitFeaturesInSep (cgp->sep, &gfc, FindGenesForCDS);
15535   }
15536 
15537   /* if multiple genes found, but only one exactly matches the coding region, choose that gene */
15538   if (gfc.gene_list != NULL && gfc.gene_list->next != NULL) {
15539     ReduceGeneList(sfp, &(gfc.gene_list));
15540   }
15541 
15542   if (gfc.gene_list == NULL || gfc.gene_list->data.ptrvalue == NULL
15543       || gfc.gene_list->next != NULL)
15544   {
15545     sfp = SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL, 0, 0, sfp, &fcontext);
15546     cds_label = StringSave (fcontext.label);
15547     if (StringLen (cds_label) > 20)
15548     {
15549       cds_label[20] = 0;
15550     }
15551     if (cgp->fp != NULL)
15552     {
15553       if (gfc.gene_list == NULL || gfc.gene_list->data.ptrvalue == NULL)
15554       {
15555         fprintf (cgp->fp, "No gene found for %s (%s)\n", cgp->featdeftype == FEATDEF_CDS ? "CDS" : "mRNA", cds_label);
15556       }
15557       else
15558       {
15559         fprintf (cgp->fp, "Found more than one gene for %s (%s)\n", cgp->featdeftype == FEATDEF_CDS ? "CDS" : "mRNA", cds_label);
15560       }
15561     }
15562     cds_label = MemFree (cds_label);
15563   }
15564   else
15565   {
15566     gene = gfc.gene_list->data.ptrvalue;
15567     CorrectOneCDSGenePair (sfp, gene, bsp, cgp);
15568   }
15569 
15570   gfc.gene_list = ValNodeFree (gfc.gene_list);
15571   gfc.test_loc = SeqLocFree (gfc.test_loc);
15572 }
15573 
CorrectGenesForCDSs(ButtoN b)15574 static void CorrectGenesForCDSs (ButtoN b)
15575 {
15576   CorrectGeneFormPtr cgp;
15577   Char			         path [PATH_MAX];
15578   SelStructPtr       ssp;
15579   SeqFeatPtr         gene = NULL, cds = NULL, sfp;
15580   SeqMgrFeatContext  fcontext;
15581   Boolean            cancel = FALSE;
15582   Int2               val;
15583 
15584   cgp = GetObjectExtra (b);
15585   if (cgp == NULL) return;
15586 
15587   Hide (cgp->form);
15588   WatchCursor ();
15589   Update ();
15590 
15591   cgp->setStrand = GetStatus (cgp->setStrandBtn);
15592   cgp->setInterval = GetStatus (cgp->setIntervalBtn);
15593   cgp->sep = GetTopSeqEntryForEntityID (cgp->input_entityID);
15594 
15595   val = GetValue (cgp->feature_choice_grp);
15596   switch (val) {
15597     case 1:
15598       cgp->featdeftype = FEATDEF_CDS;
15599       break;
15600     case 2:
15601       cgp->featdeftype = FEATDEF_mRNA;
15602       break;
15603     case 3:
15604       cgp->featdeftype = FEATDEF_ncRNA;
15605       break;
15606   }
15607 
15608   /* set up tmp file if a log has been requested */
15609   if (GetStatus (cgp->logChangesBtn))
15610   {
15611     TmpNam (path);
15612     cgp->fp = FileOpen (path, "wb");
15613   }
15614   else
15615   {
15616     cgp->fp = NULL;
15617   }
15618 
15619   if (GetStatus (cgp->correct_selected_pair))
15620   {
15621     ssp = ObjMgrGetSelected ();
15622     while (ssp != NULL && ! cancel)
15623     {
15624       if(ssp->itemtype == OBJ_SEQFEAT)
15625       {
15626         sfp = SeqMgrGetDesiredFeature (cgp->input_entityID, NULL, ssp->itemID, 0, NULL, &fcontext);
15627         if(sfp != NULL && sfp->idx.subtype == cgp->featdeftype)
15628         {
15629           if (cds == NULL)
15630           {
15631             cds = sfp;
15632           }
15633           else
15634           {
15635             if (cgp->featdeftype == FEATDEF_CDS) {
15636               Message (MSG_ERROR, "You have selected more than one CDS!");
15637             } else {
15638               Message (MSG_ERROR, "You have selected more than one mRNA!");
15639             }
15640             cancel = TRUE;
15641           }
15642         }
15643         else if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE)
15644         {
15645           if (gene == NULL)
15646           {
15647             gene = sfp;
15648           }
15649           else
15650           {
15651             Message (MSG_ERROR, "You have selected more than one gene!");
15652             cancel = TRUE;
15653           }
15654         }
15655       }
15656       ssp = ssp->next;
15657     }
15658 
15659     if (!cancel && cds != NULL && gene != NULL)
15660     {
15661       CorrectOneCDSGenePair (cds, gene, NULL, cgp);
15662     }
15663     else if (!cancel)
15664     {
15665       if (cgp->featdeftype == FEATDEF_CDS) {
15666         Message (MSG_ERROR, "You need to select one CDS and one gene");
15667       } else {
15668         Message (MSG_ERROR, "You need to select one mRNA and one gene");
15669       }
15670     }
15671   }
15672   else
15673   {
15674     cgp->constraint = DialogToPointer (cgp->constraint_dlg);
15675     VisitFeaturesInSep (cgp->sep, cgp, CorrectOneCDSGene);
15676     cgp->constraint = ConstraintChoiceSetFree (cgp->constraint);
15677   }
15678 
15679   /* close, display, and remove log file */
15680   if (cgp->fp != NULL)
15681   {
15682     FileClose (cgp->fp);
15683     cgp->fp = NULL;
15684     LaunchGeneralTextViewer (path, "Gene Change Log");
15685     FileRemove (path);
15686   }
15687 
15688   ObjMgrSetDirtyFlag (cgp->input_entityID, TRUE);
15689   ObjMgrSendMsg (OM_MSG_UPDATE, cgp->input_entityID, 0, 0);
15690   ArrowCursor ();
15691   Update ();
15692 
15693   if (GetStatus (cgp->leave_dlg_up))
15694   {
15695     Show (cgp->form);
15696   }
15697   else
15698   {
15699     Remove (cgp->form);
15700   }
15701 
15702 }
15703 
15704 
ChangeCorrectOnlySelected(ButtoN b)15705 static void ChangeCorrectOnlySelected (ButtoN b)
15706 {
15707   CorrectGeneFormPtr cgp;
15708 
15709   cgp = (CorrectGeneFormPtr) GetObjectExtra(b);
15710   if (cgp == NULL)
15711   {
15712     return;
15713   }
15714   if (GetStatus (cgp->correct_selected_pair)) {
15715     Disable (cgp->constraint_dlg);
15716   } else {
15717     Enable (cgp->constraint_dlg);
15718   }
15719 }
15720 
15721 
CorrectGenesBaseForm(BaseFormPtr bfp)15722 static void CorrectGenesBaseForm (BaseFormPtr bfp)
15723 {
15724   CorrectGeneFormPtr cgp;
15725   WindoW             w;
15726   GrouP              g, c;
15727   ButtoN             b;
15728 
15729   cgp = MemNew (sizeof (CorrectGeneFormData));
15730   if (cgp == NULL) return;
15731 
15732   w = FixedWindow (-50, -33, -20, -10, "Correct Genes",
15733                    StdCloseWindowProc);
15734   SetObjectExtra (w, cgp, StdCleanupFormProc);
15735   cgp->form = (ForM) w;
15736 
15737   cgp->input_entityID = bfp->input_entityID;
15738   cgp->input_itemID = bfp->input_itemID;
15739   cgp->input_itemtype = bfp->input_itemtype;
15740 
15741   g = HiddenGroup (w, -1, 0, NULL);
15742   SetGroupSpacing (g, 10, 10);
15743   cgp->setIntervalBtn = CheckBox (g, "Set gene interval to match", NULL);
15744   SetStatus (cgp->setIntervalBtn, TRUE);
15745   cgp->setStrandBtn = CheckBox (g, "Set gene strand to match", NULL);
15746   SetStatus (cgp->setStrandBtn, TRUE);
15747   cgp->logChangesBtn = CheckBox (g, "Log gene changes", NULL);
15748   SetStatus (cgp->logChangesBtn, FALSE);
15749 
15750   cgp->feature_choice_grp = HiddenGroup (g, 3, 0, NULL);
15751   RadioButton (cgp->feature_choice_grp, "CDS");
15752   RadioButton (cgp->feature_choice_grp, "mRNA");
15753   RadioButton (cgp->feature_choice_grp, "ncRNA");
15754   SetValue (cgp->feature_choice_grp, 1);
15755 
15756   cgp->correct_selected_pair = CheckBox (g, "Correct only selected feature-gene pair", ChangeCorrectOnlySelected);
15757   SetObjectExtra (cgp->correct_selected_pair, cgp, NULL);
15758   cgp->constraint_dlg = ComplexConstraintDialog (g, NULL, NULL);
15759   ChangeComplexConstraintFieldType (cgp->constraint_dlg, FieldType_cds_gene_prot, NULL, Macro_feature_type_any);
15760 
15761   c = HiddenGroup (g, 3, 0, NULL);
15762   b = DefaultButton(c, "Accept", CorrectGenesForCDSs);
15763   SetObjectExtra(b, cgp, NULL);
15764   PushButton (c, "Cancel", StdCancelButtonProc);
15765   cgp->leave_dlg_up = CheckBox (c, "Leave Dialog Up", NULL);
15766 
15767   AlignObjects (ALIGN_CENTER,
15768                 (HANDLE) cgp->setIntervalBtn,
15769                 (HANDLE) cgp->setStrandBtn,
15770                 (HANDLE) cgp->feature_choice_grp,
15771                 (HANDLE) cgp->correct_selected_pair,
15772                 (HANDLE) cgp->constraint_dlg,
15773 	              (HANDLE) c, NULL);
15774   RealizeWindow(w);
15775   Show(w);
15776   Update();
15777 }
15778 
15779 
CorrectGenes(IteM i)15780 static void CorrectGenes (IteM i)
15781 {
15782   BaseFormPtr        bfp;
15783 
15784 #ifdef WIN_MAC
15785   bfp = currentFormDataPtr;
15786 #else
15787   bfp = GetObjectExtra (i);
15788 #endif
15789   if (bfp == NULL) return;
15790 
15791   CorrectGenesBaseForm (bfp);
15792 }
15793 
15794 
ResetAllGenes(SeqEntryPtr sep,Boolean doMinus,Boolean doPlus,FILE * fp)15795 static void ResetAllGenes (SeqEntryPtr sep,
15796 			Boolean doMinus, Boolean doPlus, FILE *fp)
15797 {
15798   SeqEntryPtr		sep_index;
15799   SeqFeatPtr		gene;
15800   SeqFeatPtr		cds;
15801   SeqMgrFeatContext  fcontext;
15802   SeqMgrFeatContext  cdscontext;
15803   CharPtr		genename;
15804   BioseqSetPtr		bssp;
15805   BioseqPtr		bsp;
15806   SeqLocPtr		slp;
15807   SeqLocPtr		tmpslp;
15808   Boolean               cds_partial5, cds_partial3;
15809   Boolean               partial5, partial3, partial_flag;
15810 
15811   if (sep == NULL) return;
15812   if ( IS_Bioseq_set (sep))
15813   {
15814     bssp = (BioseqSetPtr) sep->data.ptrvalue;
15815     for (sep_index = bssp->seq_set;
15816 	sep_index != NULL;
15817 	sep_index = sep_index->next)
15818     {
15819       ResetAllGenes ( sep_index, doMinus, doPlus, fp);
15820     }
15821     return;
15822   }
15823   else if ( IS_Bioseq(sep))
15824   {
15825     bsp = (BioseqPtr) sep->data.ptrvalue;
15826     gene = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_GENE, 0, &fcontext);
15827     while (gene != NULL)
15828     {
15829       if (fcontext.strand == Seq_strand_minus && !doMinus)
15830         continue;
15831       if (fcontext.strand != Seq_strand_minus && !doPlus)
15832         continue;
15833       slp = NULL;
15834       partial3 = FALSE;
15835       partial5 = FALSE;
15836       partial_flag = FALSE;
15837       /* look for next feature, starting right after the gene */
15838       /* an overlapping CDS won't occur before the gene in the indexing */
15839       cds = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_CDREGION, 0, &cdscontext);
15840       while (cds != NULL)
15841       {
15842         if (((fcontext.strand == Seq_strand_minus
15843              && cdscontext.strand == Seq_strand_minus)
15844             || (fcontext.strand != Seq_strand_minus
15845              && cdscontext.strand != Seq_strand_minus))
15846             && SeqLocAinB (cds->location, gene->location) > -1)
15847         {
15848           CheckSeqLocForPartial (cds->location, &cds_partial5, &cds_partial3);
15849           partial5 |= cds_partial5;
15850           partial3 |= cds_partial3;
15851           partial_flag |= cds->partial;
15852           tmpslp = SeqLocMerge (bsp, cds->location, slp, TRUE, TRUE, FALSE);
15853           if (tmpslp == NULL) return;
15854           SeqLocFree (slp);
15855           slp = tmpslp;
15856         }
15857         cds = SeqMgrGetNextFeature (bsp, cds, SEQFEAT_CDREGION, 0,
15858 					&cdscontext);
15859       }
15860 
15861       if (slp != NULL)
15862       {
15863         SetSeqLocPartial (slp, partial5, partial3);
15864         if (fp != NULL
15865           && (SeqLocStart (gene->location) != SeqLocStart (slp)
15866             || SeqLocStop (gene->location) != SeqLocStop (slp)))
15867         {
15868           genename = GetGeneName ((GeneRefPtr) gene->data.value.ptrvalue);
15869           if (genename == NULL)
15870           {
15871             fprintf (fp, "Unnamed gene ");
15872             LogLocation (&fcontext, fp);
15873           }
15874           else
15875           {
15876             fprintf (fp, "Gene %s", genename);
15877           }
15878           fprintf (fp, " reset to CDS interval\n");
15879         }
15880         SeqLocFree (gene->location);
15881         gene->location = slp;
15882         gene->partial = partial_flag;
15883       }
15884       gene = SeqMgrGetNextFeature (bsp, gene, SEQFEAT_GENE, 0, &fcontext);
15885     }
15886   }
15887 }
15888 
ExtendGeneMessageProc(ForM f,Int2 mssg)15889 static void ExtendGeneMessageProc (ForM f, Int2 mssg)
15890 {
15891   ExtendGeneFormPtr	egfp;
15892 
15893   egfp = (ExtendGeneFormPtr) GetObjectExtra(f);
15894   if (egfp != NULL) {
15895     if (egfp->appmessage != NULL) {
15896       egfp->appmessage (f, mssg);
15897     }
15898   }
15899 }
15900 
CleanupExtendGenePage(GraphiC g,VoidPtr data)15901 static void CleanupExtendGenePage (GraphiC g, VoidPtr data)
15902 
15903 {
15904   ExtendGeneFormPtr  egfp;
15905 
15906   egfp = (ExtendGeneFormPtr) data;
15907   if (egfp != NULL) {
15908     if (egfp->item_list != NULL)
15909       MemFree (egfp->item_list);
15910   }
15911   StdCleanupFormProc (g, data);
15912 }
15913 
makeGeneXref(SeqFeatPtr sfpr,SeqFeatPtr sfpg)15914 static void makeGeneXref (SeqFeatPtr sfpr, SeqFeatPtr sfpg)
15915 {
15916   SeqFeatXrefPtr  curr;
15917   GeneRefPtr      grp;
15918   SeqFeatXrefPtr  PNTR last;
15919   SeqFeatXrefPtr  next;
15920   SeqFeatXrefPtr  xref;
15921 
15922   if (sfpr == NULL || sfpg == NULL || sfpg->data.choice != SEQFEAT_GENE) return;
15923   grp = (GeneRefPtr) sfpg->data.value.ptrvalue;
15924   if (grp == NULL) return;
15925   last = (SeqFeatXrefPtr PNTR) &(sfpr->xref);
15926   curr = sfpr->xref;
15927   while (curr != NULL) {
15928     next = curr->next;
15929     if (curr->data.choice == SEQFEAT_GENE) {
15930       *last = next;
15931       curr->next = NULL;
15932       SeqFeatXrefFree (curr);
15933     } else {
15934       last = &(curr->next);
15935     }
15936     curr = next;
15937   }
15938   grp = GeneRefDup (grp);
15939   if (grp == NULL) return;
15940   xref = SeqFeatXrefNew ();
15941   sfpr->xref = xref;
15942   if (xref != NULL) {
15943     xref->data.choice = SEQFEAT_GENE;
15944     xref->data.value.ptrvalue = (Pointer) grp;
15945   }
15946 }
15947 
extendGeneInStreamOnStrand(ExtendGeneFormPtr egfp,BioseqPtr bsp,SeqFeatPtr GeneToExtend,SeqFeatPtr FarthestRegulator,Boolean stream,Boolean isPlusStrand)15948 static void extendGeneInStreamOnStrand(ExtendGeneFormPtr egfp,
15949 					BioseqPtr bsp,
15950 					SeqFeatPtr GeneToExtend,
15951 					SeqFeatPtr FarthestRegulator,
15952 					Boolean stream,
15953 					Boolean isPlusStrand)
15954 {
15955   SeqLocPtr		slp;
15956   Int2			item_index;
15957 
15958   /* extend previous minus gene to last minus_upstream_regulator */
15959   slp = SeqLocMerge (bsp,
15960   	GeneToExtend->location, FarthestRegulator->location,
15961 	TRUE, TRUE, FALSE);
15962   if (slp == NULL) return;
15963   GeneToExtend->location = SeqLocFree (GeneToExtend->location);
15964   GeneToExtend->location = slp;
15965   for (item_index = 0 ; item_index < NUM_REGULATORY_ITEMS; item_index++)
15966   {
15967     if (list_of_regulatory_items[item_index].upstream == stream)
15968     {
15969       if(isPlusStrand)
15970       {
15971         if (egfp->item_list[item_index].plus_sfp != NULL)
15972         {
15973           /* Make XRefs for all stream plus regulators */
15974           makeGeneXref (egfp->item_list[item_index].plus_sfp, GeneToExtend);
15975 
15976           /* Then reset the stream plus pointers */
15977           egfp->item_list[item_index].plus_sfp = NULL;
15978         }
15979       }
15980       else
15981       {
15982         if (egfp->item_list[item_index].minus_sfp != NULL)
15983         {
15984           /* Make XRefs for all stream minus regulators */
15985           makeGeneXref (egfp->item_list[item_index].minus_sfp, GeneToExtend);
15986 
15987           /* Then reset the stream minus pointers */
15988           egfp->item_list[item_index].minus_sfp = NULL;
15989         }
15990       }
15991     }
15992   }
15993 }
15994 
15995 typedef struct featureloginfo {
15996   SeqMgrFeatContext	context;
15997   CharPtr		featurename;
15998 } FeatureLogInfo, FAR *FeatureLogInfoPtr;
15999 
16000 typedef struct strandloginfo {
16001   FeatureLogInfo	upstream;
16002   FeatureLogInfo	downstream;
16003 } StrandLogInfo, FAR *StrandLogInfoPtr;
16004 
LogExtend(SeqFeatPtr gene,SeqMgrFeatContextPtr genecontext,StrandLogInfoPtr log_info,Boolean doLogUnextended,FILE * fp)16005 static void LogExtend (SeqFeatPtr gene, SeqMgrFeatContextPtr genecontext,
16006 		StrandLogInfoPtr log_info, Boolean doLogUnextended, FILE *fp)
16007 {
16008   GeneRefPtr grp;
16009   CharPtr genename;
16010 
16011   if (fp == NULL) return;
16012 
16013   if (gene == NULL) return;
16014 
16015   grp = (GeneRefPtr) gene->data.value.ptrvalue;
16016   if (grp == NULL) return;
16017 
16018   if (!doLogUnextended && log_info->upstream.featurename == NULL && log_info->downstream.featurename == NULL)
16019     return;
16020 
16021   fprintf (fp, "Gene ");
16022   genename = GetGeneName (grp);
16023   if (genename != NULL)
16024   {
16025     fprintf (fp, "%s", genename);
16026   }
16027   else
16028   {
16029     LogLocation (genecontext, fp);
16030   }
16031 
16032   if (log_info->upstream.featurename == NULL && log_info->downstream.featurename == NULL)
16033   {
16034     fprintf (fp, " not extended\n");
16035   }
16036   else if (log_info->upstream.featurename != NULL)
16037   {
16038     fprintf (fp, " extended to %s ", log_info->upstream.featurename);
16039     LogLocation (&(log_info->upstream.context), fp);
16040     if (log_info->downstream.featurename != NULL)
16041     {
16042       fprintf (fp, ", %s ", log_info->downstream.featurename);
16043       LogLocation (&(log_info->downstream.context), fp);
16044     }
16045     fprintf (fp, "\n");
16046   }
16047   else
16048   {
16049     fprintf (fp, " extended to %s ", log_info->downstream.featurename);
16050     LogLocation (&(log_info->downstream.context), fp);
16051     fprintf (fp, "\n");
16052   }
16053 }
16054 
ExtendGenesOnSequence(SeqEntryPtr sep,ExtendGeneFormPtr egfp)16055 static void ExtendGenesOnSequence (SeqEntryPtr sep, ExtendGeneFormPtr egfp)
16056 {
16057   SeqEntryPtr		sep_index;
16058   BioseqSetPtr		bssp;
16059   BioseqPtr		bsp;
16060   SeqFeatPtr		sfp;
16061   SeqMgrFeatContext	fcontext;
16062   SeqFeatPtr		plus_upstream_regulator;
16063   SeqFeatPtr		plus_downstream_regulator;
16064   SeqFeatPtr		plus_gene;
16065   SeqFeatPtr		minus_upstream_regulator;
16066   SeqFeatPtr		minus_downstream_regulator;
16067   SeqFeatPtr		minus_gene;
16068   Int2			item_index;
16069   GeneRefPtr		grp;
16070   SeqFeatPtr		overlapping_gene;
16071   StrandLogInfo		previous_plus_log;
16072   StrandLogInfo		next_plus_log;
16073   StrandLogInfo		previous_minus_log;
16074   StrandLogInfo		next_minus_log;
16075 
16076   if (sep == NULL) return;
16077   if ( IS_Bioseq_set (sep))
16078   {
16079     bssp = (BioseqSetPtr) sep->data.ptrvalue;
16080     for (sep_index = bssp->seq_set;
16081 	sep_index != NULL;
16082 	sep_index = sep_index->next)
16083     {
16084       ExtendGenesOnSequence ( sep_index, egfp);
16085     }
16086     return;
16087   }
16088   else if ( ! IS_Bioseq(sep))
16089   {
16090     return;
16091   }
16092 
16093   bsp = (BioseqPtr) sep->data.ptrvalue;
16094 
16095   /* Walk through gene sequence, extending genes to specified regulatory */
16096   /* elements, respecting strand direction */
16097   sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
16098 
16099   /* Loop through all features */
16100 
16101   plus_upstream_regulator = NULL;
16102   plus_downstream_regulator = NULL;
16103   plus_gene = NULL;
16104   minus_upstream_regulator = NULL;
16105   minus_downstream_regulator = NULL;
16106   minus_gene = NULL;
16107   previous_plus_log.upstream.featurename = NULL;
16108   previous_plus_log.downstream.featurename = NULL;
16109   previous_minus_log.upstream.featurename = NULL;
16110   previous_minus_log.downstream.featurename = NULL;
16111   next_plus_log.upstream.featurename = NULL;
16112   next_plus_log.downstream.featurename = NULL;
16113   next_minus_log.upstream.featurename = NULL;
16114   next_minus_log.downstream.featurename = NULL;
16115 
16116   while (NULL != sfp)
16117   {
16118     /* determine whether item has gene reference */
16119     overlapping_gene = SeqMgrGetOverlappingGene (sfp->location, NULL);
16120     grp = SeqMgrGetGeneXref (sfp);
16121 
16122     /* process strand items separately */
16123     if (fcontext.strand == Seq_strand_minus)
16124     {
16125       if (egfp->doMinusStrand)
16126       {
16127         if (fcontext.featdeftype == FEATDEF_GENE)
16128         {
16129           if (minus_gene != NULL && minus_upstream_regulator != NULL)
16130           {
16131             /* extend previous minus gene to last minus_upstream_regulator */
16132             extendGeneInStreamOnStrand(egfp, bsp, minus_gene,
16133 					minus_upstream_regulator,
16134 					TRUE, FALSE);
16135           }
16136           LogExtend (minus_gene, &fcontext, &previous_minus_log,
16137 			egfp->doLogUnextendedEvents, egfp->fp);
16138           previous_minus_log = next_minus_log;
16139           next_minus_log.upstream.featurename = NULL;
16140           next_minus_log.downstream.featurename = NULL;
16141           minus_gene = sfp;
16142           if (minus_gene != NULL && minus_downstream_regulator != NULL)
16143           {
16144             /* extend this minus gene to minus_downstream_regulator */
16145             extendGeneInStreamOnStrand(egfp, bsp, minus_gene,
16146 					minus_downstream_regulator,
16147 					FALSE, FALSE);
16148           }
16149           minus_upstream_regulator = NULL;
16150           minus_downstream_regulator = NULL;
16151         }
16152         else
16153         {
16154           for (item_index = 0;
16155   		       item_index < NUM_REGULATORY_ITEMS;
16156   		       item_index++)
16157   		  {
16158   		    if (list_of_regulatory_items[item_index].iFeatDef == fcontext.featdeftype)
16159             {
16160               if (egfp->item_list[item_index].item_value &&
16161 		          ((grp == NULL && overlapping_gene == NULL) || egfp->doStealFeatures))
16162               {
16163                 if (list_of_regulatory_items[item_index].upstream)
16164                 {
16165                   minus_upstream_regulator = sfp;
16166                   previous_minus_log.upstream.featurename = list_of_regulatory_items[item_index].label;
16167                   previous_minus_log.upstream.context = fcontext;
16168                 }
16169                 else
16170                 {
16171                   /* found downstream regulator */
16172                   if (minus_downstream_regulator == NULL)
16173                   {
16174                     minus_downstream_regulator = sfp;
16175                     next_minus_log.downstream.featurename = list_of_regulatory_items[item_index].label;
16176                     next_minus_log.downstream.context = fcontext;
16177                   }
16178                 }
16179                 egfp->item_list[item_index].minus_sfp = sfp;
16180               }
16181             }
16182           }
16183         }
16184       }
16185     }
16186     else /* treat all other conditions as plus strand */
16187     {
16188       if (egfp->doPlusStrand)
16189       {
16190         if (fcontext.featdeftype == FEATDEF_GENE)
16191         {
16192           if (plus_gene != NULL && plus_downstream_regulator != NULL)
16193           {
16194             /* extend previous plus gene to last plus_downstream_regulator */
16195             extendGeneInStreamOnStrand(egfp, bsp, plus_gene,
16196 					plus_downstream_regulator,
16197 					FALSE, TRUE);
16198           }
16199           LogExtend (plus_gene, &fcontext, &previous_plus_log,
16200 			egfp->doLogUnextendedEvents,egfp->fp);
16201           plus_gene = sfp;
16202           if (plus_gene != NULL && plus_upstream_regulator != NULL)
16203           {
16204             /* extend previous plus gene to first plus_upstream_regulator */
16205             extendGeneInStreamOnStrand(egfp, bsp, plus_gene,
16206 					plus_upstream_regulator,
16207 					TRUE, TRUE);
16208           }
16209           plus_upstream_regulator = NULL;
16210           plus_downstream_regulator = NULL;
16211           previous_plus_log = next_plus_log;
16212           next_plus_log.upstream.featurename = NULL;
16213           next_plus_log.downstream.featurename = NULL;
16214         }
16215         else
16216         {
16217           for (item_index = 0;
16218 		       item_index < NUM_REGULATORY_ITEMS;
16219 		       item_index++ )
16220 		  {
16221 		    if (list_of_regulatory_items[item_index].iFeatDef == fcontext.featdeftype)
16222             {
16223               if (egfp->item_list[item_index].item_value &&
16224                   ((grp == NULL && overlapping_gene == NULL) || egfp->doStealFeatures))
16225               {
16226                 if (list_of_regulatory_items[item_index].upstream)
16227                 {
16228                   if (plus_upstream_regulator == NULL)
16229                   {
16230                     plus_upstream_regulator = sfp;
16231                     next_plus_log.upstream.featurename = list_of_regulatory_items[item_index].label;
16232                     next_plus_log.upstream.context = fcontext;
16233                   }
16234                 }
16235                 else
16236                 {
16237                   /* found downstream regulator */
16238                   plus_downstream_regulator = sfp;
16239                   previous_plus_log.downstream.featurename = list_of_regulatory_items[item_index].label;
16240                   previous_plus_log.downstream.context = fcontext;
16241                 }
16242                 egfp->item_list[item_index].plus_sfp = sfp;
16243               }
16244             }
16245           }
16246         }
16247       }
16248     }
16249     sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext);
16250   }
16251 
16252   /* extend final minus strand gene */
16253   if (minus_gene != NULL && minus_upstream_regulator != NULL && egfp->doMinusStrand)
16254   {
16255     /* extend this minus gene to minus_upstream_regulator */
16256     extendGeneInStreamOnStrand(egfp, bsp, minus_gene,
16257 					minus_upstream_regulator,
16258 					TRUE, FALSE);
16259   }
16260   LogExtend (minus_gene, &fcontext, &previous_minus_log,
16261 			egfp->doLogUnextendedEvents,egfp->fp);
16262 
16263   /* extend final plus strand gene */
16264   if (plus_gene != NULL && plus_downstream_regulator != NULL && egfp->doPlusStrand)
16265   {
16266     /* extend this plus gene to plus_downstream_regulator */
16267     extendGeneInStreamOnStrand(egfp, bsp, plus_gene,
16268 					plus_downstream_regulator,
16269 					FALSE, TRUE);
16270   }
16271   LogExtend (plus_gene, &fcontext, &previous_plus_log,
16272 			egfp->doLogUnextendedEvents,egfp->fp);
16273 
16274 }
16275 
DoExtendGene(ButtoN b)16276 static void DoExtendGene (ButtoN b)
16277 {
16278   SeqEntryPtr		sep;
16279   ExtendGeneFormPtr	egfp;
16280   Char			path [PATH_MAX];
16281   Int2			item_index;
16282 
16283   egfp = GetObjectExtra (b);
16284   if (egfp == NULL) return;
16285   Hide (egfp->form);
16286   WatchCursor ();
16287   Update ();
16288 
16289   egfp->doLogEvents = GetStatus (egfp->LogEvents);
16290   egfp->doLogUnextendedEvents = GetStatus (egfp->LogUnextendedEvents);
16291   if (egfp->doLogEvents)
16292   {
16293     TmpNam (path);
16294     egfp->fp = FileOpen (path, "wb");
16295   }
16296   else
16297   {
16298     egfp->fp = NULL;
16299   }
16300 
16301   /* get button statuses */
16302   for (item_index = 0; item_index < NUM_REGULATORY_ITEMS; item_index ++ )
16303   {
16304     egfp->item_list[item_index].item_value = GetStatus (egfp->item_list[item_index].item_button);
16305   }
16306 
16307   egfp->doPlusStrand = GetStatus (egfp->PlusStrand);
16308   egfp->doMinusStrand = GetStatus (egfp->MinusStrand);
16309   egfp->doResetGenes = GetStatus (egfp->ResetGenes);
16310   egfp->doStealFeatures = GetStatus (egfp->StealFeatures);
16311 
16312   sep = GetTopSeqEntryForEntityID (egfp->input_entityID);
16313 
16314   if (egfp->doResetGenes)
16315   {
16316     ResetAllGenes (sep, egfp->doMinusStrand, egfp->doPlusStrand, egfp->fp);
16317     /* reindex features */
16318     SeqMgrIndexFeatures (egfp->input_entityID, NULL);
16319   }
16320 
16321   ExtendGenesOnSequence (sep, egfp);
16322 
16323   /* reindex features */
16324   SeqMgrIndexFeatures (egfp->input_entityID, NULL);
16325 
16326   /* remove redundant x-refs */
16327   SeqMgrExploreBioseqs (egfp->input_entityID, 0, NULL, RemoveGeneXrefsOnBioseqs, TRUE, TRUE, TRUE);
16328 
16329   ArrowCursor ();
16330   Update ();
16331   ObjMgrSetDirtyFlag (egfp->input_entityID, TRUE);
16332   ObjMgrSendMsg (OM_MSG_UPDATE, egfp->input_entityID, 0, 0);
16333   Remove (egfp->form);
16334   if (egfp->doLogEvents)
16335   {
16336     FileClose (egfp->fp);
16337     LaunchGeneralTextViewer (path, "Extend Gene Log");
16338     FileRemove (path);
16339   }
16340 }
16341 
16342 
DisableLogOption(ButtoN b)16343 static void DisableLogOption (ButtoN b)
16344 {
16345   ExtendGeneFormPtr	egfp;
16346   Boolean	DoLogEvents;
16347 
16348   egfp = (ExtendGeneFormPtr) GetObjectExtra (b);
16349   DoLogEvents = GetStatus (egfp->LogEvents);
16350   if (DoLogEvents)
16351   {
16352     Enable (egfp->LogUnextendedEvents);
16353   }
16354   else
16355   {
16356     SetStatus (egfp->LogUnextendedEvents, FALSE);
16357     Disable (egfp->LogUnextendedEvents);
16358   }
16359 }
16360 
ExtendGeneReg(IteM i)16361 static void ExtendGeneReg (IteM i)
16362 {
16363   BaseFormPtr        bfp;
16364   SeqEntryPtr        sep;
16365   ExtendGeneFormPtr	egfp;
16366   WindoW	w;
16367   GrouP		g;
16368   GrouP		h;
16369   GrouP		j;
16370   GrouP		k;
16371   GrouP		UpstreamGroup;
16372   GrouP		DownstreamGroup;
16373   GrouP		m;
16374   GrouP		c;
16375   ButtoN	b;
16376   Int2		item_index;
16377 
16378 #ifdef WIN_MAC
16379   bfp = currentFormDataPtr;
16380 #else
16381   bfp = GetObjectExtra (i);
16382 #endif
16383   if (bfp == NULL) return;
16384   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
16385   if (sep == NULL) return;
16386   egfp = (ExtendGeneFormPtr) MemNew (sizeof (ExtendGeneFormData));
16387   if (egfp == NULL) return;
16388   w = FixedWindow (-50, -33, -20, -10, "Extend Gene", StdCloseWindowProc);
16389   SetObjectExtra (w, egfp, CleanupExtendGenePage);
16390   egfp->form = (ForM) w;
16391   egfp->formmessage = ExtendGeneMessageProc;
16392 
16393   egfp->input_entityID = bfp->input_entityID;
16394   egfp->input_itemID = bfp->input_itemID;
16395   egfp->input_itemtype = bfp->input_itemtype;
16396 
16397   g = HiddenGroup (w, -1, 0, NULL);
16398   SetGroupSpacing (g, 10, 10);
16399 
16400   h = HiddenGroup (g, 0, 1, NULL);
16401   egfp->PlusStrand = CheckBox(h, "Extend on Plus Strand", NULL);
16402   SetStatus(egfp->PlusStrand, TRUE);
16403   egfp->MinusStrand = CheckBox(h, "Extend on Minus Strand", NULL);
16404   SetStatus(egfp->MinusStrand, TRUE);
16405   k = HiddenGroup (g, 0, 2, NULL);
16406   egfp->ResetGenes = CheckBox (k, "Reset Genes to CDS Locations before Extending", NULL);
16407   SetStatus (egfp->ResetGenes, FALSE);
16408   egfp->StealFeatures = CheckBox (k, "Reassign Features from Other Genes", NULL);
16409   SetStatus (egfp->StealFeatures, FALSE);
16410 
16411   egfp->item_list = MemNew (NUM_REGULATORY_ITEMS * sizeof (ExtendGeneFormLocalItemData));
16412   if (egfp->item_list == NULL) return;
16413   for (item_index = 0; item_index < NUM_REGULATORY_ITEMS; item_index ++)
16414   {
16415     egfp->item_list[item_index].item_button = NULL;
16416     egfp->item_list[item_index].item_value =
16417 		list_of_regulatory_items[item_index].item_value;
16418     egfp->item_list[item_index].plus_sfp = NULL;
16419     egfp->item_list[item_index].minus_sfp = NULL;
16420   }
16421 
16422   j = HiddenGroup (g, 1, 0, NULL);
16423   SetGroupSpacing (j, 10, 10);
16424   UpstreamGroup = NormalGroup (j, 0, 4, "Upstream", NULL, NULL);
16425   for(item_index = 0; item_index < NUM_REGULATORY_ITEMS; item_index ++)
16426   {
16427     if(list_of_regulatory_items[item_index].upstream)
16428     {
16429       egfp->item_list[item_index].item_button = CheckBox(UpstreamGroup, list_of_regulatory_items[item_index].label, NULL);
16430       SetStatus(egfp->item_list[item_index].item_button,
16431               list_of_regulatory_items[item_index].item_value);
16432     }
16433   }
16434   DownstreamGroup = NormalGroup (j, 4, 0, "Downstream", NULL, NULL);
16435   for(item_index = 0; item_index < NUM_REGULATORY_ITEMS; item_index ++)
16436   {
16437     if(! list_of_regulatory_items[item_index].upstream)
16438     {
16439       egfp->item_list[item_index].item_button = CheckBox(DownstreamGroup, list_of_regulatory_items[item_index].label, NULL);
16440       SetStatus(egfp->item_list[item_index].item_button,
16441               list_of_regulatory_items[item_index].item_value);
16442     }
16443   }
16444   m = HiddenGroup (g, 2, 0, NULL);
16445   egfp->LogEvents = CheckBox (m, "Log Changes", DisableLogOption);
16446   SetObjectExtra(egfp->LogEvents, egfp, NULL);
16447   SetStatus (egfp->LogEvents, FALSE);
16448   egfp->LogUnextendedEvents = CheckBox (m, "Log Unextended Genes", NULL);
16449   SetStatus (egfp->LogUnextendedEvents, FALSE);
16450   Disable (egfp->LogUnextendedEvents);
16451 
16452   c = HiddenGroup (g, 2, 0, NULL);
16453   b = DefaultButton(c, "Accept", DoExtendGene);
16454   SetObjectExtra(b, egfp, NULL);
16455   PushButton (c, "Cancel", StdCancelButtonProc);
16456 
16457   AlignObjects (ALIGN_CENTER, (HANDLE) h, (HANDLE) k,
16458 	(HANDLE) j, (HANDLE) m, (HANDLE) c, NULL);
16459   RealizeWindow(w);
16460   Show(w);
16461   Update();
16462 }
16463 
ResynchronizeCDSPartials(IteM i)16464 static void ResynchronizeCDSPartials (IteM i)
16465 
16466 {
16467   BaseFormPtr  bfp;
16468   SeqEntryPtr  sep;
16469 
16470 #ifdef WIN_MAC
16471   bfp = currentFormDataPtr;
16472 #else
16473   bfp = GetObjectExtra (i);
16474 #endif
16475   if (bfp == NULL) return;
16476   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
16477   if (sep == NULL) return;
16478   WatchCursor ();
16479   Update ();
16480   ResynchCodingRegionPartials (sep);
16481   ArrowCursor ();
16482   Update ();
16483   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
16484   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
16485 }
16486 
ResynchronizeMRNAPartials(IteM i)16487 static void ResynchronizeMRNAPartials (IteM i)
16488 
16489 {
16490   BaseFormPtr  bfp;
16491   SeqEntryPtr  sep;
16492 
16493 #ifdef WIN_MAC
16494   bfp = currentFormDataPtr;
16495 #else
16496   bfp = GetObjectExtra (i);
16497 #endif
16498   if (bfp == NULL) return;
16499   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
16500   if (sep == NULL) return;
16501   WatchCursor ();
16502   Update ();
16503   ResynchMessengerRNAPartials (sep);
16504   ArrowCursor ();
16505   Update ();
16506   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
16507   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
16508 }
16509 
ResynchronizePeptidePartials(IteM i)16510 static void ResynchronizePeptidePartials (IteM i)
16511 
16512 {
16513   BaseFormPtr  bfp;
16514   SeqEntryPtr  sep;
16515 
16516 #ifdef WIN_MAC
16517   bfp = currentFormDataPtr;
16518 #else
16519   bfp = GetObjectExtra (i);
16520 #endif
16521   if (bfp == NULL) return;
16522   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
16523   if (sep == NULL) return;
16524   WatchCursor ();
16525   Update ();
16526   ResynchProteinPartials (sep);
16527   ArrowCursor ();
16528   Update ();
16529   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
16530   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
16531 }
16532 
TrimProtsCallback(BioseqPtr bsp,Pointer userdata)16533 static void TrimProtsCallback (BioseqPtr bsp, Pointer userdata)
16534 
16535 {
16536   SeqFeatPtr    sfp;
16537   SeqIntPtr     sintp;
16538   SeqLocPtr     slp;
16539   SeqMgrFeatContext context;
16540 
16541   if (bsp == NULL || !ISA_aa (bsp->mol)) return;
16542 
16543   for (sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_PROT, 0, &context);
16544        sfp != NULL;
16545        sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_PROT, 0, &context)) {
16546     slp = SeqLocFindNext (sfp->location, NULL);
16547     if (slp != NULL && slp->choice == SEQLOC_INT) {
16548       sintp = (SeqIntPtr) slp->data.ptrvalue;
16549       if (sintp != NULL) {
16550         if (sintp->from == 0 && sintp->to > bsp->length - 1) {
16551           sintp->to = bsp->length - 1;
16552         }
16553       }
16554     }
16555   }
16556 }
16557 
TrimProtFeatLengthsEx(Uint2 entityID)16558 static void TrimProtFeatLengthsEx (Uint2 entityID)
16559 
16560 {
16561   SeqEntryPtr  sep;
16562 
16563   sep = GetTopSeqEntryForEntityID (entityID);
16564   if (sep == NULL) return;
16565   VisitBioseqsInSep (sep, NULL, TrimProtsCallback);
16566   ObjMgrSetDirtyFlag (entityID, TRUE);
16567   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
16568 }
16569 
TrimProtFeatLengths(IteM i)16570 static void TrimProtFeatLengths (IteM i)
16571 
16572 {
16573   BaseFormPtr  bfp;
16574 
16575 #ifdef WIN_MAC
16576   bfp = (BaseFormPtr) currentFormDataPtr;
16577 #else
16578   bfp = (BaseFormPtr) GetObjectExtra (i);
16579 #endif
16580   if (bfp == NULL) return;
16581   TrimProtFeatLengthsEx (bfp->input_entityID);
16582 }
16583 
UnsetPartialForTruncatedProteins(SeqFeatPtr sfp,Pointer userdata)16584 static void UnsetPartialForTruncatedProteins (SeqFeatPtr sfp, Pointer userdata)
16585 {
16586   Boolean partial5, partial3;
16587   ProtRefPtr prp;
16588   CharPtr    new_name;
16589   BoolPtr    change_name;
16590 
16591   if (sfp == NULL || userdata == NULL) return;
16592   change_name = (BoolPtr) userdata;
16593   CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
16594   SetSeqLocPartial (sfp->location, partial5, FALSE);
16595   sfp->partial = partial5;
16596   if (*change_name) {
16597     prp = sfp->data.value.ptrvalue;
16598     if (prp != NULL && prp->name != NULL
16599         && prp->name->data.ptrvalue != NULL
16600         && StringNCmp (prp->name->data.ptrvalue, "truncated ", 10) != 0) {
16601       new_name = (CharPtr) MemNew (StringLen (prp->name->data.ptrvalue)
16602                                    + 11);
16603       if (new_name != NULL) {
16604         sprintf (new_name, "truncated %s", (CharPtr) prp->name->data.ptrvalue);
16605         MemFree (prp->name->data.ptrvalue);
16606         prp->name->data.ptrvalue = new_name;
16607       }
16608     }
16609   }
16610 }
16611 
UnsetCDSPartialForTruncatedProteins(SeqFeatPtr sfp,Pointer userdata)16612 static void UnsetCDSPartialForTruncatedProteins (SeqFeatPtr sfp, Pointer userdata)
16613 {
16614   Boolean     partial5, partial3;
16615   BioseqPtr   product_bsp, prot_bsp;
16616   CdRegionPtr crp;
16617   Int4        cds_len;
16618 
16619   if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION
16620       || sfp->location == NULL) return;
16621   if ((prot_bsp = (BioseqPtr)userdata) == NULL) return;
16622 
16623   product_bsp = BioseqFindFromSeqLoc (sfp->product);
16624   if (product_bsp == prot_bsp) {
16625     CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
16626     SetSeqLocPartial (sfp->location, partial5, FALSE);
16627     sfp->partial = partial5;
16628 
16629     cds_len = (prot_bsp->length + 1) * 3 ;
16630     crp = (CdRegionPtr) sfp->data.value.ptrvalue;
16631     if (crp != NULL)
16632     {
16633       if (crp->frame == 2)
16634       {
16635         cds_len += 1;
16636       }
16637       else if (crp->frame == 3)
16638       {
16639         cds_len += 2;
16640       }
16641     }
16642     sfp->location = TruncateLocation (sfp->location, cds_len);
16643   }
16644 }
16645 
16646 typedef struct truncprotsdata {
16647   Uint2       entityID;
16648   WindoW      w;
16649   ButtoN      reset_genes_btn;
16650   ButtoN      trim_prot_feats_btn;
16651   ButtoN      change_name_btn;
16652   ButtoN      retranslate_cds_btn;
16653   ButtoN      truncate_mrna_btn;
16654 
16655   SeqEntryPtr sep;
16656   Boolean     change_name;
16657   Boolean     trim_prot_feats;
16658   Boolean     retranslate_cds;
16659   Boolean     reset_genes;
16660   Boolean     truncate_mrna;
16661 } TruncProtsData, PNTR TruncProtsPtr;
16662 
TruncProtsCallback(BioseqPtr bsp,Pointer userdata)16663 static void TruncProtsCallback (BioseqPtr bsp, Pointer userdata)
16664 
16665 {
16666   ByteStorePtr  bs;
16667   BioseqPtr     cds_bsp = NULL;
16668   Int4          i;
16669   Int2          residue;
16670   SeqPortPtr    spp;
16671   Boolean       found_stop;
16672   TruncProtsPtr tpp;
16673   SeqFeatPtr    cds;
16674   SeqFeatPtr    gene = NULL, mRNA = NULL;
16675   GeneRefPtr    xref;
16676   SeqMgrFeatContext context;
16677   Boolean           partial5 = FALSE, partial3 = FALSE;
16678   Boolean           oldpartial5 = FALSE, oldpartial3 = FALSE;
16679   Boolean           need_change = FALSE;
16680   SeqLocPtr         slp;
16681   RecompData        rd;
16682 
16683   if (bsp == NULL) return;
16684   if (! ISA_aa (bsp->mol)) return;
16685   if (bsp->repr != Seq_repr_raw && bsp->repr != Seq_repr_const) return;
16686 
16687   if ((tpp = (TruncProtsPtr)userdata) == NULL) return;
16688 
16689   /* get coding region for this protein */
16690   cds = SeqMgrGetCDSgivenProduct (bsp, NULL);
16691 
16692   if (cds != NULL)
16693   {
16694 
16695     cds_bsp = BioseqFindFromSeqLoc (cds->location);
16696 
16697     CheckSeqLocForPartial (cds->location, &partial5, &partial3);
16698     /* get gene for coding region */
16699     xref = SeqMgrGetGeneXref (cds);
16700     if (xref == NULL)
16701     {
16702       gene = SeqMgrGetOverlappingGene (cds->location, &context);
16703     }
16704 
16705     /* get mRNA for coding region */
16706     mRNA = SeqMgrGetOverlappingmRNA (cds->location, &context);
16707   }
16708 
16709   bs = BSNew (1000);
16710   if (bs == NULL) return;
16711   spp = SeqPortNew (bsp, 0, -1, 0, Seq_code_ncbieaa);
16712   if (spp == NULL) return;
16713 
16714   i = 0;
16715   residue = SeqPortGetResidue (spp);
16716   while (i < bsp->length && residue != '*') {
16717     BSPutByte (bs, residue);
16718     i++;
16719     residue = SeqPortGetResidue (spp);
16720   }
16721   if (residue == '*') {
16722     found_stop = TRUE;
16723   } else {
16724     found_stop = FALSE;
16725   }
16726 
16727   if (i >= bsp->length || !found_stop)
16728   {
16729     bs = BSFree (bs);
16730     SeqPortFree (spp);
16731     return;
16732   }
16733 
16734   SeqPortFree (spp);
16735   bsp->seq_data = SeqDataFree (bsp->seq_data, bsp->seq_data_type);
16736   bsp->seq_data = (SeqDataPtr) bs;
16737   bsp->length = BSLen (bs);
16738   bsp->seq_data_type = Seq_code_ncbieaa;
16739 
16740   VisitFeaturesOnBsp (bsp, (Pointer) &(tpp->change_name),
16741                       UnsetPartialForTruncatedProteins);
16742   VisitFeaturesInSep (tpp->sep, bsp,  UnsetCDSPartialForTruncatedProteins);
16743   /* trim protein features */
16744   TrimProtsCallback (bsp, NULL);
16745 
16746   if (cds != NULL)
16747   {
16748     rd.no_stop_at_end_of_complete_cds = FALSE;
16749     rd.include_stop = FALSE;
16750     /* retranslate coding region associated with this protein, if requested */
16751     if (tpp->retranslate_cds)
16752     {
16753       RetranslateOneCDS (cds, tpp->entityID, rd.include_stop, rd.no_stop_at_end_of_complete_cds);
16754     }
16755   }
16756 
16757   /* reset gene location if requested */
16758   if (tpp->reset_genes && gene != NULL && (mRNA == NULL || tpp->truncate_mrna))
16759   {
16760     need_change = FALSE;
16761     slp = SeqLocMerge (cds_bsp, cds->location, NULL, TRUE, TRUE, FALSE);
16762     if (SeqLocCompare (slp, gene->location) != SLC_A_EQ_B)
16763     {
16764       need_change = TRUE;
16765     }
16766     CheckSeqLocForPartial (gene->location, &oldpartial5, &oldpartial3);
16767     CheckSeqLocForPartial (cds->location, &partial5, &partial3);
16768     if (oldpartial5 != partial5 || oldpartial3 != partial3)
16769     {
16770       need_change = TRUE;
16771     }
16772     if (need_change)
16773     {
16774       SetSeqLocPartial (slp, partial5, partial3);
16775       SeqLocFree (gene->location);
16776       gene->location = slp;
16777       gene->partial = partial5 || partial3;
16778     }
16779     else
16780     {
16781       slp = SeqLocFree (slp);
16782     }
16783   }
16784 
16785 
16786   if (tpp->truncate_mrna && mRNA != NULL)
16787   {
16788     mRNA->location = TruncateLocation (mRNA->location, SeqLocLen (cds->location));
16789   }
16790 }
16791 
16792 
DoTruncateProteins(ButtoN b)16793 static void DoTruncateProteins (ButtoN b)
16794 {
16795   TruncProtsPtr     tpp;
16796 
16797   tpp = (TruncProtsPtr) GetObjectExtra (b);
16798   if (tpp == NULL)
16799   {
16800     return;
16801   }
16802 
16803   tpp->sep = GetTopSeqEntryForEntityID (tpp->entityID);
16804   if (tpp->sep == NULL) return;
16805 
16806 
16807   tpp->change_name = GetStatus (tpp->change_name_btn);
16808   tpp->trim_prot_feats = GetStatus (tpp->trim_prot_feats_btn);
16809   tpp->retranslate_cds = GetStatus (tpp->retranslate_cds_btn);
16810   tpp->reset_genes = GetStatus (tpp->reset_genes_btn);
16811   tpp->truncate_mrna = GetStatus (tpp->truncate_mrna_btn);
16812 
16813   VisitBioseqsInSep (tpp->sep, tpp, TruncProtsCallback);
16814 
16815   ObjMgrSetDirtyFlag (tpp->entityID, TRUE);
16816   ObjMgrSendMsg (OM_MSG_UPDATE, tpp->entityID, 0, 0);
16817   Remove (tpp->w);
16818 }
16819 
TruncateProteins(IteM i)16820 static void TruncateProteins (IteM i)
16821 {
16822   BaseFormPtr       bfp;
16823   TruncProtsPtr     tpp;
16824   GrouP             g, k, c;
16825   ButtoN            b;
16826 
16827 #ifdef WIN_MAC
16828   bfp = currentFormDataPtr;
16829 #else
16830   bfp = GetObjectExtra (i);
16831 #endif
16832   if (bfp == NULL) return;
16833 
16834   tpp = (TruncProtsPtr) MemNew (sizeof (TruncProtsData));
16835   if (tpp == NULL) return;
16836 
16837   tpp->w = FixedWindow (-50, -33, -20, -10, "Truncate Proteins at Stop Codons",
16838                    StdCloseWindowProc);
16839   SetObjectExtra (tpp->w, tpp, StdCleanupExtraProc);
16840   tpp->entityID = bfp->input_entityID;
16841 
16842   g = HiddenGroup (tpp->w, -1, 0, NULL);
16843   SetGroupSpacing (g, 10, 10);
16844   k = HiddenGroup (g, 0, 6, NULL);
16845   SetGroupSpacing (g, 10, 10);
16846   tpp->trim_prot_feats_btn = CheckBox (k, "Trim Protein Features", NULL);
16847   SetStatus (tpp->trim_prot_feats_btn, TRUE);
16848   tpp->retranslate_cds_btn = CheckBox (k, "Retranslate Coding Regions for Truncated Proteins", NULL);
16849   SetStatus (tpp->retranslate_cds_btn, TRUE);
16850   tpp->truncate_mrna_btn = CheckBox (k, "Truncate Associated mRNA Features", NULL);
16851   SetStatus (tpp->truncate_mrna_btn, FALSE);
16852   tpp->reset_genes_btn = CheckBox (k, "Reset Genes", NULL);
16853   SetStatus (tpp->reset_genes_btn, TRUE);
16854   tpp->change_name_btn = CheckBox (k, "Prepend 'Truncated' to Protein Name", NULL);
16855   SetStatus (tpp->change_name_btn, TRUE);
16856 
16857   c = HiddenGroup (g, 2, 0, NULL);
16858   b = DefaultButton(c, "Accept", DoTruncateProteins);
16859   SetObjectExtra(b, tpp, NULL);
16860   PushButton (c, "Cancel", StdCancelButtonProc);
16861 
16862   AlignObjects (ALIGN_CENTER, (HANDLE) k, (HANDLE) c, NULL);
16863   RealizeWindow(tpp->w);
16864   Show(tpp->w);
16865   Update();
16866 }
16867 
ExtendProtsForBioseq(BioseqPtr bsp,Int4 orig_len)16868 static void ExtendProtsForBioseq (BioseqPtr bsp, Int4 orig_len)
16869 {
16870   SeqFeatPtr        sfp;
16871   SeqMgrFeatContext context;
16872   SeqLocPtr         slp;
16873   SeqIntPtr         sintp;
16874 
16875   for (sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_PROT, 0, &context);
16876        sfp != NULL;
16877        sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_PROT, 0, &context))
16878   {
16879     slp = SeqLocFindNext (sfp->location, NULL);
16880     if (slp != NULL && slp->choice == SEQLOC_INT)
16881     {
16882       sintp = (SeqIntPtr) slp->data.ptrvalue;
16883       if (sintp != NULL)
16884       {
16885         if (sintp->to == orig_len)
16886         {
16887           sintp->to = bsp->length - 1;
16888         }
16889       }
16890     }
16891   }
16892 }
16893 
ExtendProtsCallback(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)16894 static void ExtendProtsCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
16895 
16896 {
16897   BioseqPtr         bsp, cds_bsp = NULL;
16898   TruncProtsPtr     tpp;
16899   SeqFeatPtr        cds;
16900   SeqFeatPtr        gene = NULL, mRNA = NULL;
16901   GeneRefPtr        xref;
16902   SeqMgrFeatContext context;
16903   Boolean           partial5 = FALSE, partial3 = FALSE;
16904   Boolean           oldpartial5 = FALSE, oldpartial3 = FALSE;
16905   Boolean           need_change = FALSE;
16906   SeqLocPtr         slp;
16907   CharPtr           new_prot = NULL;
16908   Int4              orig_len, orig_cds_len;
16909   Int4              start, stop, len_extended;
16910   Uint1             strand;
16911 
16912   if (! IS_Bioseq (sep)) return;
16913   bsp = (BioseqPtr) sep->data.ptrvalue;
16914   if (bsp == NULL) return;
16915   if (! ISA_aa (bsp->mol)) return;
16916   if (bsp->repr != Seq_repr_raw && bsp->repr != Seq_repr_const) return;
16917 
16918   if ((tpp = (TruncProtsPtr)mydata) == NULL) return;
16919 
16920   orig_len = bsp->length;
16921   /* get coding region for this protein */
16922   cds = SeqMgrGetCDSgivenProduct (bsp, NULL);
16923   if (cds == NULL)
16924   {
16925     return;
16926   }
16927 
16928   orig_cds_len = SeqLocLen (cds->location);
16929 
16930   cds_bsp = BioseqFindFromSeqLoc (cds->location);
16931 
16932   /* get gene for coding region */
16933   xref = SeqMgrGetGeneXref (cds);
16934   if (xref == NULL)
16935   {
16936     gene = SeqMgrGetOverlappingGene (cds->location, &context);
16937   }
16938 
16939   /* get mRNA for coding region */
16940   mRNA = SeqMgrGetOverlappingmRNA (cds->location, &context);
16941 
16942   new_prot = ExtendProtein3 (cds, cds->idx.entityID, FALSE);
16943   len_extended = SeqLocLen (cds->location) - orig_cds_len;
16944   if (new_prot == NULL
16945       || (StringLen (new_prot) == bsp->length && len_extended == 0))
16946   {
16947     new_prot = MemFree (new_prot);
16948     return;
16949   }
16950 
16951   CheckSeqLocForPartial (cds->location, &partial5, &partial3);
16952   if (!partial3) {
16953     VisitFeaturesOnBsp (bsp, (Pointer) &(tpp->change_name),
16954                         UnsetPartialForTruncatedProteins);
16955   }
16956 
16957   /* retranslate coding region associated with this protein, if requested */
16958   if (tpp->retranslate_cds)
16959   {
16960     RetranslateOneCDS (cds, tpp->entityID, FALSE, FALSE);
16961 
16962     /* extend protein features if requested */
16963     if (tpp->trim_prot_feats)
16964     {
16965       ExtendProtsForBioseq (bsp, orig_len);
16966     }
16967   }
16968 
16969   /* reset gene location if requested */
16970   if (tpp->reset_genes && gene != NULL && (mRNA == NULL || tpp->truncate_mrna))
16971   {
16972     need_change = FALSE;
16973     slp = SeqLocMerge (cds_bsp, cds->location, NULL, TRUE, TRUE, FALSE);
16974     if (SeqLocCompare (slp, gene->location) != SLC_A_EQ_B)
16975     {
16976       need_change = TRUE;
16977     }
16978     CheckSeqLocForPartial (gene->location, &oldpartial5, &oldpartial3);
16979     CheckSeqLocForPartial (cds->location, &partial5, &partial3);
16980     if (oldpartial5 != partial5 || oldpartial3 != partial3)
16981     {
16982       need_change = TRUE;
16983     }
16984     if (need_change)
16985     {
16986       SetSeqLocPartial (slp, partial5, partial3);
16987       SeqLocFree (gene->location);
16988       gene->location = slp;
16989     }
16990     else
16991     {
16992       slp = SeqLocFree (slp);
16993     }
16994   }
16995 
16996   if (tpp->truncate_mrna && mRNA != NULL)
16997   {
16998     start = GetOffsetInBioseq (mRNA->location, cds_bsp, SEQLOC_START);
16999     stop = GetOffsetInBioseq (mRNA->location, cds_bsp, SEQLOC_STOP);
17000     strand = SeqLocStrand (mRNA->location);
17001 
17002     mRNA->location = ExpandSeqLoc (start, stop + len_extended,
17003                                    strand, cds_bsp, mRNA->location);
17004 
17005   }
17006 }
17007 
DoExtendProteins(ButtoN b)17008 static void DoExtendProteins (ButtoN b)
17009 {
17010   TruncProtsPtr     tpp;
17011 
17012   tpp = (TruncProtsPtr) GetObjectExtra (b);
17013   if (tpp == NULL)
17014   {
17015     return;
17016   }
17017 
17018   tpp->sep = GetTopSeqEntryForEntityID (tpp->entityID);
17019   if (tpp->sep == NULL) return;
17020 
17021 
17022   tpp->change_name = FALSE;
17023   tpp->trim_prot_feats = GetStatus (tpp->trim_prot_feats_btn);
17024   tpp->retranslate_cds = GetStatus (tpp->retranslate_cds_btn);
17025   tpp->reset_genes = GetStatus (tpp->reset_genes_btn);
17026   tpp->truncate_mrna = GetStatus (tpp->truncate_mrna_btn);
17027 
17028   SeqEntryExplore (tpp->sep, tpp, ExtendProtsCallback);
17029 
17030   ObjMgrSetDirtyFlag (tpp->entityID, TRUE);
17031   ObjMgrSendMsg (OM_MSG_UPDATE, tpp->entityID, 0, 0);
17032   Remove (tpp->w);
17033 }
17034 
ExtendProteins(IteM i)17035 static void ExtendProteins (IteM i)
17036 {
17037   BaseFormPtr       bfp;
17038   TruncProtsPtr     tpp;
17039   GrouP             g, k, c;
17040   ButtoN            b;
17041 
17042 #ifdef WIN_MAC
17043   bfp = currentFormDataPtr;
17044 #else
17045   bfp = GetObjectExtra (i);
17046 #endif
17047   if (bfp == NULL) return;
17048 
17049   tpp = (TruncProtsPtr) MemNew (sizeof (TruncProtsData));
17050   if (tpp == NULL) return;
17051 
17052   tpp->w = FixedWindow (-50, -33, -20, -10, "Extend Proteins to Stop Codons",
17053                    StdCloseWindowProc);
17054   SetObjectExtra (tpp->w, tpp, StdCleanupExtraProc);
17055   tpp->entityID = bfp->input_entityID;
17056 
17057   g = HiddenGroup (tpp->w, -1, 0, NULL);
17058   SetGroupSpacing (g, 10, 10);
17059   k = HiddenGroup (g, 0, 6, NULL);
17060   SetGroupSpacing (g, 10, 10);
17061   tpp->trim_prot_feats_btn = CheckBox (k, "Extend Protein Features", NULL);
17062   SetStatus (tpp->trim_prot_feats_btn, TRUE);
17063   tpp->retranslate_cds_btn = CheckBox (k, "Retranslate Coding Regions for Extended Proteins", NULL);
17064   SetStatus (tpp->retranslate_cds_btn, TRUE);
17065   tpp->truncate_mrna_btn = CheckBox (k, "Extend Associated mRNA Features", NULL);
17066   SetStatus (tpp->truncate_mrna_btn, FALSE);
17067   tpp->reset_genes_btn = CheckBox (k, "Reset Genes", NULL);
17068   SetStatus (tpp->reset_genes_btn, TRUE);
17069   tpp->change_name_btn = NULL;
17070 
17071   c = HiddenGroup (g, 2, 0, NULL);
17072   b = DefaultButton(c, "Accept", DoExtendProteins);
17073   SetObjectExtra(b, tpp, NULL);
17074   PushButton (c, "Cancel", StdCancelButtonProc);
17075 
17076   AlignObjects (ALIGN_CENTER, (HANDLE) k, (HANDLE) c, NULL);
17077   RealizeWindow(tpp->w);
17078   Show(tpp->w);
17079   Update();
17080 
17081 }
17082 
TrimNsFromNucsCommon(Uint2 entityID)17083 static void TrimNsFromNucsCommon (Uint2 entityID)
17084 
17085 {
17086   LogInfoPtr lip;
17087 
17088   lip = OpenLog ("Trimmed Locations");
17089   TrimNsFromNucsInSeqEntry (GetTopSeqEntryForEntityID (entityID), lip);
17090 
17091   CloseLog (lip);
17092   lip = FreeLog (lip);
17093 
17094   ObjMgrSetDirtyFlag (entityID, TRUE);
17095   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
17096 }
17097 
TrimNsFromNucs(IteM i)17098 static void TrimNsFromNucs (IteM i)
17099 {
17100   BaseFormPtr     bfp;
17101 
17102 #ifdef WIN_MAC
17103   bfp = (BaseFormPtr) currentFormDataPtr;
17104 #else
17105   bfp = (BaseFormPtr) GetObjectExtra (i);
17106 #endif
17107   if (bfp == NULL) return;
17108   TrimNsFromNucsCommon (bfp->input_entityID);
17109 
17110 }
17111 
TrimNsFromNucsToolBtn(ButtoN b)17112 static void TrimNsFromNucsToolBtn (ButtoN b)
17113 
17114 {
17115   BaseFormPtr  bfp;
17116 
17117   if (b == NULL) return;
17118   bfp = (BaseFormPtr) GetObjectExtra (b);
17119   if (bfp == NULL) return;
17120   TrimNsFromNucsCommon (bfp->input_entityID);
17121 }
17122 
ApplySourceQualToolBtn(ButtoN b)17123 static void ApplySourceQualToolBtn (ButtoN b)
17124 
17125 {
17126   BaseFormPtr  bfp;
17127 
17128   if (b == NULL) return;
17129   bfp = (BaseFormPtr) GetObjectExtra (b);
17130   if (bfp == NULL) return;
17131   SingleAECRMacroAction (bfp->input_entityID, TRUE, ActionChoice_apply, FieldType_source_qual);
17132 }
17133 
s_NextQualifies(SeqFeatPtr sfp,BioseqPtr bsp,Int2 level,SeqMgrFeatContextPtr context)17134 static Boolean s_NextQualifies (SeqFeatPtr sfp,
17135 				BioseqPtr  bsp,
17136 				Int2       level,
17137 				SeqMgrFeatContextPtr context)
17138 {
17139   SeqFeatPtr        nextSfp;
17140   SeqMgrFeatContext fContext;
17141   GBQualPtr         gbq;
17142   Boolean           isvector;
17143 
17144   /* Get the next feature */
17145 
17146   fContext = *context;
17147   nextSfp = SeqMgrGetNextFeature (bsp, sfp, 0, FEATDEF_misc_feature,
17148 				  &fContext);
17149   if (nextSfp == NULL)
17150     return FALSE;
17151 
17152   /* Make sure that it's a Vector Contamination misc feat */
17153 
17154   for (isvector = FALSE, gbq = nextSfp->qual; gbq != NULL; gbq = gbq->next) {
17155     if (StringCmp (gbq->qual, "standard_name") == 0) {
17156       if (StringCmp (gbq->val, "Vector Contamination") == 0) {
17157         isvector = TRUE;
17158       }
17159     }
17160   }
17161   if (! isvector)
17162     return FALSE;
17163 
17164   /* Check the match level against the level that we're looking for */
17165 
17166   for (isvector = FALSE, gbq = nextSfp->qual; gbq != NULL; gbq = gbq->next) {
17167     if (StringCmp (gbq->qual, "phenotype") == 0) {
17168       if (StringCmp (gbq->val, "Strong match") == 0) {
17169         isvector = TRUE;
17170       } else if (StringCmp (gbq->val, "Moderate match") == 0 && level > 1) {
17171         isvector = TRUE;
17172       } else if (StringCmp (gbq->val, "Weak match") == 0 && level > 2) {
17173         isvector = TRUE;
17174       }
17175     }
17176   }
17177   if (! isvector)
17178     return FALSE;
17179 
17180   /* If we've made it this far, then the next feature */
17181   /* qualifies to be overwritten with N's.            */
17182 
17183   return TRUE;
17184 }
17185 
17186 
ToolBtn1(ButtoN b)17187 static void ToolBtn1 (ButtoN b)
17188 
17189 {
17190   BaseFormPtr  bfp;
17191 
17192   bfp = (BaseFormPtr) GetObjectExtra (b);
17193   if (bfp == NULL) return;
17194 
17195   SaveSeqSubmitProc (bfp, FALSE);
17196 }
17197 
ToolBtn2(ButtoN b)17198 static void ToolBtn2 (ButtoN b)
17199 
17200 {
17201   BaseFormPtr  bfp;
17202 
17203   bfp = (BaseFormPtr) GetObjectExtra (b);
17204   if (bfp == NULL) return;
17205 
17206   AutoDefBaseFormCommon (bfp, FALSE, TRUE, FALSE);
17207 }
17208 
ToolBtn3(ButtoN b)17209 static void ToolBtn3 (ButtoN b)
17210 
17211 {
17212   BaseFormPtr  bfp;
17213 
17214   bfp = (BaseFormPtr) GetObjectExtra (b);
17215   if (bfp == NULL) return;
17216 
17217   ForceCleanupBtn (NULL, b, FALSE);
17218 }
17219 
ToolBtn4(ButtoN b)17220 static void ToolBtn4 (ButtoN b)
17221 
17222 {
17223   BaseFormPtr  bfp;
17224 
17225   bfp = (BaseFormPtr) GetObjectExtra (b);
17226   if (bfp == NULL) return;
17227 
17228   CommonAddOrgOrModsToDefLines (NULL, 0, 0, b);
17229 }
17230 
ToolBtn5(ButtoN b)17231 static void ToolBtn5 (ButtoN b)
17232 
17233 {
17234   BaseFormPtr  bfp;
17235 
17236   bfp = (BaseFormPtr) GetObjectExtra (b);
17237   if (bfp == NULL) return;
17238 
17239   WatchCursor ();
17240   Update ();
17241   GatherProcLaunch (OMPROC_EDIT, FALSE, bfp->input_entityID, bfp->input_itemID,
17242                     bfp->input_itemtype, OBJ_SEQFEAT, FEATDEF_CDS, 0, 0);
17243   ArrowCursor ();
17244   Update ();
17245 }
17246 
ToolBtn6(ButtoN b)17247 static void ToolBtn6 (ButtoN b)
17248 
17249 {
17250   BaseFormPtr  bfp;
17251 
17252   bfp = (BaseFormPtr) GetObjectExtra (b);
17253   if (bfp == NULL) return;
17254 
17255 
17256   WatchCursor ();
17257   Update ();
17258   GatherProcLaunch (OMPROC_EDIT, FALSE, bfp->input_entityID, bfp->input_itemID,
17259                     bfp->input_itemtype, OBJ_SEQFEAT, FEATDEF_rRNA, 0, 0);
17260   ArrowCursor ();
17261   Update ();
17262 }
17263 
17264 
ToolBtnGene(ButtoN b)17265 static void ToolBtnGene (ButtoN b)
17266 
17267 {
17268   BaseFormPtr  bfp;
17269 
17270   bfp = (BaseFormPtr) GetObjectExtra (b);
17271   if (bfp == NULL) return;
17272 
17273 
17274   WatchCursor ();
17275   Update ();
17276   GatherProcLaunch (OMPROC_EDIT, FALSE, bfp->input_entityID, bfp->input_itemID,
17277                     bfp->input_itemtype, OBJ_SEQFEAT, FEATDEF_GENE, 0, 0);
17278   ArrowCursor ();
17279   Update ();
17280 }
17281 
17282 
ToolBtn7(ButtoN b)17283 static void ToolBtn7 (ButtoN b)
17284 
17285 {
17286   BaseFormPtr  bfp;
17287 
17288   bfp = (BaseFormPtr) GetObjectExtra (b);
17289   if (bfp == NULL) return;
17290 
17291   MRnaFromCdsProc (bfp->input_entityID);
17292 }
17293 
ToolBtn8(ButtoN b)17294 static void ToolBtn8 (ButtoN b)
17295 
17296 {
17297   BaseFormPtr  bfp;
17298   BioseqPtr    bsp;
17299 
17300   bfp = (BaseFormPtr) GetObjectExtra (b);
17301   if (bfp == NULL) return;
17302   bsp =  GetBioseqGivenIDs (bfp->input_entityID, bfp->input_itemID, bfp->input_itemtype);
17303   if (bsp == NULL) return;
17304   LaunchOrfViewer (bsp, bfp->input_entityID, bfp->input_itemID, FALSE);
17305 }
17306 
ToolBtn9(ButtoN b)17307 static void ToolBtn9 (ButtoN b)
17308 
17309 {
17310   BaseFormPtr  bfp;
17311 
17312   bfp = (BaseFormPtr) GetObjectExtra (b);
17313   if (bfp == NULL) return;
17314 
17315 
17316   WatchCursor ();
17317   Update ();
17318   GatherProcLaunch (OMPROC_EDIT, FALSE, bfp->input_entityID, bfp->input_itemID,
17319                     bfp->input_itemtype, OBJ_SEQFEAT, FEATDEF_misc_feature, 0, 0);
17320   ArrowCursor ();
17321   Update ();
17322 }
17323 
ToolBtn10(ButtoN b)17324 static void ToolBtn10 (ButtoN b)
17325 
17326 {
17327   BaseFormPtr  bfp;
17328 
17329   bfp = (BaseFormPtr) GetObjectExtra (b);
17330   if (bfp == NULL) return;
17331 
17332   SUCCommonProc (NULL, FALSE, TRUE, TRUE, b);
17333 }
17334 
ToolBtn11(ButtoN b)17335 static void ToolBtn11 (ButtoN b)
17336 
17337 {
17338   BaseFormPtr  bfp;
17339   Int2         mssgsub;
17340 
17341   bfp = (BaseFormPtr) GetObjectExtra (b);
17342   if (bfp == NULL) return;
17343 
17344   mssgsub = RegisterFormMenuItemName ("SequinEditSubmitterItem");
17345   SendMessageToForm (bfp->form, mssgsub);
17346 }
17347 
MakePubOnTopSep(GatherContextPtr gcp)17348 static Boolean MakePubOnTopSep (GatherContextPtr gcp)
17349 
17350 {
17351   Pointer  ptrvalue;
17352 
17353   if (gcp == NULL) return TRUE;
17354   ptrvalue = (Pointer) gcp->userdata;
17355   if (ptrvalue == NULL) return TRUE;
17356   if (gcp->thistype == OBJ_BIOSEQ || gcp->thistype == OBJ_BIOSEQSET) {
17357     if (ptrvalue == gcp->thisitem) {
17358 
17359       WatchCursor ();
17360       Update ();
17361       GatherProcLaunch (OMPROC_EDIT, FALSE, gcp->entityID, gcp->itemID,
17362                         gcp->thistype, OBJ_SEQDESC, Seq_descr_pub, 0, 0);
17363       ArrowCursor ();
17364       Update ();
17365       return FALSE;
17366     }
17367   }
17368   return TRUE;
17369 }
17370 
ToolBtn12(ButtoN b)17371 static void ToolBtn12 (ButtoN b)
17372 
17373 {
17374   BaseFormPtr  bfp;
17375   GatherScope  gs;
17376   SeqEntryPtr  sep;
17377 
17378   bfp = (BaseFormPtr) GetObjectExtra (b);
17379   if (bfp == NULL) return;
17380 
17381   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
17382   if (sep == NULL || sep->data.ptrvalue == NULL) return;
17383 
17384   MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
17385   gs.seglevels = 1;
17386   MemSet((Pointer) (gs.ignore), (int) (TRUE), (size_t) (OBJ_MAX * sizeof (Boolean)));
17387   gs.ignore[OBJ_BIOSEQ] = FALSE;
17388   gs.ignore[OBJ_BIOSEQSET] = FALSE;
17389   gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
17390   GatherEntity (bfp->input_entityID, (Pointer) sep->data.ptrvalue, MakePubOnTopSep, &gs);
17391 }
17392 
ToolBtn13(ButtoN b)17393 static void ToolBtn13 (ButtoN b)
17394 
17395 {
17396   BaseFormPtr  bfp;
17397 
17398   bfp = (BaseFormPtr) GetObjectExtra (b);
17399   if (bfp == NULL) return;
17400 
17401   EditPubsEx (bfp);
17402 }
17403 
ToolBtn14(ButtoN b)17404 static void ToolBtn14 (ButtoN b)
17405 
17406 {
17407   BaseFormPtr  bfp;
17408 
17409   bfp = (BaseFormPtr) GetObjectExtra (b);
17410   if (bfp == NULL) return;
17411 
17412   ValSeqEntryForm (bfp->form);
17413 }
17414 
ToolBtn15(ButtoN b)17415 static void ToolBtn15 (ButtoN b)
17416 
17417 {
17418   BaseFormPtr  bfp;
17419 
17420   bfp = (BaseFormPtr) GetObjectExtra (b);
17421   if (bfp == NULL) return;
17422 
17423   VSeqMgrShow ();
17424 }
17425 
ToolBtn16(ButtoN b)17426 static void ToolBtn16 (ButtoN b)
17427 
17428 {
17429   BaseFormPtr  bfp;
17430 
17431   bfp = (BaseFormPtr) GetObjectExtra (b);
17432   if (bfp == NULL) return;
17433 
17434   AddCitSubForUpdateProc (bfp);
17435 }
17436 
17437 
InsertSetEntityID(Uint2 entityID,Uint1 set_type)17438 static void InsertSetEntityID (Uint2 entityID, Uint1 set_type)
17439 {
17440   SeqEntryPtr   sep;
17441   BioseqSetPtr  bssp, newbssp;
17442   ObjMgrDataPtr omdptop;
17443   ObjMgrData    omdata;
17444   Uint2         parenttype;
17445   Pointer       parentptr;
17446 
17447   sep = GetTopSeqEntryForEntityID (entityID);
17448   if (sep == NULL) {
17449     return;
17450   }
17451 
17452   WatchCursor ();
17453   Update ();
17454 
17455   SaveSeqEntryObjMgrData (sep, &omdptop, &omdata);
17456   GetSeqEntryParent (sep, &parentptr, &parenttype);
17457   RemoveDupGenBankSets (sep);
17458   if (IS_Bioseq_set (sep)) {
17459     bssp = (BioseqSetPtr) sep->data.ptrvalue;
17460     if (bssp != NULL) {
17461       newbssp = InsetNewSet (bssp, set_type);
17462       if (newbssp != NULL) {
17463         newbssp->descr = bssp->descr;
17464         bssp->descr = NULL;
17465         newbssp->annot = bssp->annot;
17466         bssp->annot = NULL;
17467       }
17468     }
17469   }
17470   SeqMgrLinkSeqEntry (sep, parenttype, parentptr);
17471   RestoreSeqEntryObjMgrData (sep, omdptop, &omdata);
17472   ObjMgrSetDirtyFlag (entityID, TRUE);
17473   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
17474 
17475   ArrowCursor ();
17476   Update ();
17477 }
17478 
17479 
17480 typedef struct addsetform {
17481   FORM_MESSAGE_BLOCK
17482   PopuP class_control;
17483 } AddSetFormData, PNTR AddSetFormPtr;
17484 
InsertSetBtn(ButtoN b)17485 static void InsertSetBtn (ButtoN b) {
17486   AddSetFormPtr frm;
17487   UIEnum        val;
17488 
17489   frm = (AddSetFormPtr) GetObjectExtra (b);
17490   if (frm == NULL) {
17491     return;
17492   }
17493 
17494   GetEnumPopup (frm->class_control, bioseqset_class_alist, &val);
17495   InsertSetEntityID (frm->input_entityID, (Uint1) val);
17496 
17497   Remove (frm->form);
17498   Update();
17499 }
17500 
17501 
AddSetToolProc(IteM i,ButtoN b)17502 static void AddSetToolProc (IteM i, ButtoN b)
17503 
17504 {
17505   BaseFormPtr  bfp = NULL;
17506   SeqEntryPtr  sep;
17507   WindoW       w;
17508   GrouP        h, c;
17509   AddSetFormPtr frm;
17510 
17511   if (b != NULL) {
17512     bfp = GetObjectExtra (b);
17513   } else {
17514 #ifdef WIN_MAC
17515     bfp = currentFormDataPtr;
17516 #else
17517     bfp = GetObjectExtra (i);
17518 #endif
17519   }
17520   if (bfp == NULL) return;
17521 
17522   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
17523   if (sep == NULL) {
17524     return;
17525   }
17526 
17527   /* get class for new set */
17528   frm = (AddSetFormPtr) MemNew (sizeof (AddSetFormData));
17529   frm->input_entityID = bfp->input_entityID;
17530   w = FixedWindow (-50, -33, -10, -10, "Bioseq Set", NULL);
17531   SetObjectExtra (w, frm, StdCleanupFormProc);
17532   frm->form = (ForM) w;
17533 
17534   h = HiddenGroup (w, -2, 0, NULL);
17535   StaticPrompt (h, "Class", 0, popupMenuHeight, programFont, 'l');
17536   frm->class_control = PopupList (h, TRUE, NULL);
17537   InitEnumPopup (frm->class_control, bioseqset_class_alist, NULL);
17538   SetEnumPopup (frm->class_control, bioseqset_class_alist, (UIEnum) BioseqseqSet_class_phy_set);
17539 
17540   c = HiddenGroup (w, 2, 0, NULL);
17541   b = DefaultButton (c, "Accept", InsertSetBtn);
17542   SetObjectExtra (b, frm, NULL);
17543   PushButton (c, "Cancel", StdCancelButtonProc);
17544   AlignObjects (ALIGN_CENTER, (HANDLE) h, (HANDLE) c, NULL);
17545   RealizeWindow (w);
17546   Show (w);
17547 }
17548 
AddSetToolBtn(ButtoN b)17549 static void AddSetToolBtn (ButtoN b)
17550 
17551 {
17552   BaseFormPtr  bfp;
17553 
17554   bfp = (BaseFormPtr) GetObjectExtra (b);
17555   if (bfp == NULL) return;
17556 
17557   AddSetToolProc (NULL, b);
17558 }
17559 
AddSetMenuItem(IteM i)17560 static void AddSetMenuItem (IteM i)
17561 
17562 {
17563   AddSetToolProc (i, NULL);
17564 }
17565 
MarkHypotheticalProteinTitles(SeqDescrPtr sdp,Pointer userdata)17566 static void MarkHypotheticalProteinTitles (SeqDescrPtr sdp, Pointer userdata)
17567 {
17568   CharPtr pDefLine;
17569   CharPtr pCh;
17570   CharPtr pMatch = "hypothetical protein";
17571   size_t match_len = StringLen(pMatch);
17572   ObjValNodePtr ovn;
17573 
17574   if (sdp == NULL || sdp->extended == 0) return;
17575   if (sdp->choice != Seq_descr_title) return;
17576   pDefLine = sdp->data.ptrvalue;
17577   if (pDefLine == NULL) return;
17578   if(StringNCmp(pDefLine, pMatch, match_len) != 0)
17579   {
17580     return;
17581   }
17582   pCh = pDefLine + match_len;
17583   if(*pCh == 0
17584 	|| (*pCh == '.' && *(pCh + 1) == 0)
17585 	|| (*pCh == ' ' && *(pCh + 1) == '['))
17586   {
17587     ovn = (ObjValNodePtr) sdp;
17588     ovn->idx.deleteme = TRUE;
17589   }
17590 }
17591 
RemoveBioseqHypotheticalProteinTitles(BioseqPtr bsp,Pointer userdata)17592 static void RemoveBioseqHypotheticalProteinTitles (BioseqPtr bsp, Pointer userdata)
17593 {
17594   if (bsp == NULL) return;
17595   if (! ISA_aa(bsp->mol)) return;
17596   VisitDescriptorsOnBsp(bsp, userdata, MarkHypotheticalProteinTitles);
17597 }
17598 
RemoveHypotheticalProteinTitles(IteM i)17599 static void RemoveHypotheticalProteinTitles (IteM i)
17600 {
17601   BaseFormPtr  bfp;
17602   SeqEntryPtr  sep;
17603 
17604 #ifdef WIN_MAC
17605   bfp = currentFormDataPtr;
17606 #else
17607   bfp = GetObjectExtra (i);
17608 #endif
17609   if (bfp == NULL) return;
17610 
17611   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
17612   if (sep == NULL) return;
17613 
17614   VisitBioseqsInSep (sep, NULL, RemoveBioseqHypotheticalProteinTitles);
17615   DeleteMarkedObjects(bfp->input_entityID, 0, NULL);
17616   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
17617   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
17618   Update ();
17619 }
17620 
RemoveProtTitlesProc(BaseFormPtr bfp)17621 static void RemoveProtTitlesProc (BaseFormPtr bfp)
17622 
17623 {
17624   BioseqPtr    bsp;
17625   SeqEntryPtr  fsep;
17626   SeqEntryPtr  sep;
17627   SeqIdPtr     sip;
17628 
17629   if (bfp == NULL) return;
17630 
17631   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
17632   if (sep == NULL) return;
17633 
17634   fsep = FindNthBioseq (sep, 1);
17635   if (fsep != NULL && IS_Bioseq (fsep)) {
17636     bsp = (BioseqPtr) fsep->data.ptrvalue;
17637     if (bsp != NULL) {
17638       for (sip = bsp->id; sip != NULL; sip = sip->next) {
17639         if (sip->choice == SEQID_OTHER) {
17640           Message (MSG_OK, "Use Remove ALL Protein Titles for RefSeq records");
17641           break;
17642         }
17643       }
17644     }
17645   }
17646 
17647   ClearProteinTitlesInNucProts (bfp->input_entityID, NULL);
17648 
17649   Update ();
17650   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
17651   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
17652 }
17653 
DoRemoveProtTitles(IteM i)17654 static void DoRemoveProtTitles (IteM i)
17655 
17656 {
17657   BaseFormPtr  bfp;
17658 
17659 #ifdef WIN_MAC
17660   bfp = currentFormDataPtr;
17661 #else
17662   bfp = GetObjectExtra (i);
17663 #endif
17664   if (bfp == NULL) return;
17665 
17666   RemoveProtTitlesProc (bfp);
17667 }
17668 
ToolBtn17(ButtoN b)17669 static void ToolBtn17 (ButtoN b)
17670 
17671 {
17672   BaseFormPtr  bfp;
17673 
17674   bfp = (BaseFormPtr) GetObjectExtra (b);
17675   if (bfp == NULL) return;
17676 
17677   RemoveProtTitlesProc (bfp);
17678 }
17679 
RemoveBioseqInconsistentProteinTitles(BioseqPtr bsp,Pointer userdata)17680 static void RemoveBioseqInconsistentProteinTitles (BioseqPtr bsp, Pointer userdata)
17681 {
17682   BioseqSetPtr       bssp;
17683   Char               buf [1001];
17684   ObjValNodePtr      ovn;
17685   CharPtr            title;
17686   ValNodePtr         vnp;
17687 
17688   if (bsp == NULL) return;
17689   if (ISA_aa (bsp->mol)) {
17690     vnp = BioseqGetSeqDescr (bsp, Seq_descr_title, NULL);
17691     if (vnp != NULL) {
17692       if (bsp->idx.parenttype == OBJ_BIOSEQSET) {
17693         bssp = (BioseqSetPtr) bsp->idx.parentptr;
17694         while (bssp != NULL && bssp->_class != BioseqseqSet_class_nuc_prot) {
17695           if (bssp->idx.parenttype == OBJ_BIOSEQSET) {
17696             bssp = (BioseqSetPtr) bssp->idx.parentptr;
17697           } else {
17698             bssp = NULL;
17699           }
17700         }
17701         if (bssp != NULL && bssp->_class == BioseqseqSet_class_nuc_prot) {
17702           title = (CharPtr) vnp->data.ptrvalue;
17703           if (NewCreateDefLineBuf (NULL, bsp, buf, sizeof (buf), TRUE, FALSE)) {
17704             if (StringICmp (buf, title) != 0) {
17705               ovn = (ObjValNodePtr) vnp;
17706               ovn->idx.deleteme = TRUE;
17707             }
17708           }
17709         }
17710       }
17711     }
17712   }
17713 }
17714 
RemoveInconsistentProteinTitles(IteM i)17715 static void RemoveInconsistentProteinTitles (IteM i)
17716 {
17717   BaseFormPtr  bfp;
17718   SeqEntryPtr  sep;
17719 
17720 #ifdef WIN_MAC
17721   bfp = currentFormDataPtr;
17722 #else
17723   bfp = GetObjectExtra (i);
17724 #endif
17725   if (bfp == NULL) return;
17726 
17727   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
17728   if (sep == NULL) return;
17729 
17730   VisitBioseqsInSep (sep, NULL, RemoveBioseqInconsistentProteinTitles);
17731   DeleteMarkedObjects(bfp->input_entityID, 0, NULL);
17732   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
17733   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
17734   Update ();
17735 }
17736 
ToolBtnOncallerTool(ButtoN b)17737 static void ToolBtnOncallerTool (ButtoN b)
17738 {
17739   CreateReportWindow (eReportTypeOnCaller);
17740 }
17741 
17742 
RemoveUnculturedNotesMenuItem(IteM i)17743 static void RemoveUnculturedNotesMenuItem (IteM i)
17744 {
17745   BaseFormPtr bfp;
17746 
17747   bfp = GetObjectExtra (i);
17748   if (bfp == NULL) return;
17749 
17750   RemoveCultureNotes (GetTopSeqEntryForEntityID (bfp->input_entityID));
17751   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
17752   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
17753   Update ();
17754 }
17755 
17756 
RemoveUnculturedNotesBtn(ButtoN b)17757 static void RemoveUnculturedNotesBtn (ButtoN b)
17758 {
17759   BaseFormPtr bfp;
17760 
17761   bfp = GetObjectExtra (b);
17762   if (bfp == NULL) return;
17763 
17764   RemoveCultureNotes (GetTopSeqEntryForEntityID (bfp->input_entityID));
17765   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
17766   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
17767   Update ();
17768 }
17769 
17770 
SqnPushButton(GrouP prnt,CharPtr title,BtnActnProc actn,BaseFormPtr bfp)17771 static ButtoN SqnPushButton (GrouP prnt, CharPtr title, BtnActnProc actn, BaseFormPtr bfp)
17772 
17773 {
17774   ButtoN  b;
17775 
17776   b = PushButton (prnt, title, actn);
17777   SetObjectExtra (b, (Pointer) bfp, NULL);
17778   return b;
17779 }
17780 
17781 static void FixCapitalizationToolBtn (ButtoN b);
17782 static void RunAutoFixScriptToolBtn (ButtoN b);
17783 
BioseqViewFormToolBar(GrouP h)17784 extern void BioseqViewFormToolBar (GrouP h)
17785 
17786 {
17787   BaseFormPtr  bfp;
17788   GrouP        g, g2, g3;
17789   ButtoN       b1, b2, b3, b4, b5, b6, b_top;
17790 
17791   bfp = (BaseFormPtr) GetObjectExtra (h);
17792   if (bfp == NULL) return;
17793   g = HiddenGroup (h, 1, 0, NULL);
17794   if (indexerVersion)
17795   {
17796     SqnPushButton (g, "Auto_Def", AutoDefToolBtn, bfp);
17797     b_top = SqnPushButton (g, "Auto_Def Options", AutoDefOptionsToolBtn, bfp);
17798     g2 = HiddenGroup (g, 2, 0, NULL);
17799     SqnPushButton (g2, "  Ad_ID  ", AutoDefStrainToolBtn, bfp);
17800     b1 = SqnPushButton (g2, "Ad_misc", AutoDefMiscFeatToolBtn, bfp);
17801 
17802     if (useTaxon) {
17803       SqnPushButton (g, "Tax_Fix/Clean_Up", ToolBtn3, bfp);
17804     }
17805     g2 = HiddenGroup (g, 2, 0, NULL);
17806     SqnPushButton (g2, "   CDS   ", ToolBtn5, bfp);
17807     b2 = SqnPushButton (g2, "rRNA", ToolBtn6, bfp);
17808     SqnPushButton (g2, "misc_feat", ToolBtn9, bfp);
17809     b3 = SqnPushButton (g2, "gene", ToolBtnGene, bfp);
17810     SqnPushButton (g, "mRna_CDS", ToolBtn7, bfp);
17811     g2 = HiddenGroup (g, 2, 0, NULL);
17812     SqnPushButton (g2, "ORF_Find", ToolBtn8, bfp);
17813     SqnPushButton (g2, " Group Explode ", GroupExplodeToolBtn, bfp);
17814 
17815     SqnPushButton (g, "SUC", ToolBtn10, bfp);
17816     SqnPushButton (g, "rRNA->DNA", RibosomalRNAToGenomicDNAToolBtn, bfp);
17817     SqnPushButton (g, "Add Set", AddSetToolBtn, bfp);
17818     SqnPushButton (g, "Remove DefLines", RemoveDefLinesToolBtn, bfp);
17819     g2 = HiddenGroup (g, 2, 0, NULL);
17820     SqnPushButton (g2, "Trim Ns", TrimNsFromNucsToolBtn, bfp);
17821     SqnPushButton (g2, "Apply Source Qual", ApplySourceQualToolBtn, bfp);
17822     g2 = HiddenGroup (g, 2, 0, NULL);
17823     SqnPushButton (g2, "Find ASN.1", FindStringProcToolBtn, bfp);
17824     b4 = SqnPushButton (g2, "Find FF", FindFlatfileProcToolBtn, bfp);
17825     SqnPushButton (g, "Local ID->Src", ParseLocalIDToSourceQual, bfp);
17826     SqnPushButton (g, "Fix Local IDs", ResolveExistingLocalIDsToolBtn, bfp);
17827 
17828     g2 = HiddenGroup (g, 2, 0, NULL);
17829     SqnPushButton (g2, "    Autofix    ", RunAutoFixScriptToolBtn, bfp);
17830     SqnPushButton (g2, "Table Reader ", NewLoadFeatureQualifierTableToolBtn, bfp);
17831     SqnPushButton (g2, "cit-sub-upd", ToolBtn16, bfp);
17832     SqnPushButton (g2, "Rm Culture Notes", RemoveUnculturedNotesBtn, bfp);
17833 
17834     g2 = HiddenGroup (g, 2, 0, NULL);
17835     SqnPushButton (g2, "Fix Caps", FixCapitalizationToolBtn, bfp);
17836     b5 = SqnPushButton (g2, "Edit Pubs", ToolBtn13, bfp);
17837     SqnPushButton (g, "rem_prot_titles", ToolBtn17, bfp);
17838     SqnPushButton (g, "Validate", ToolBtn14, bfp);
17839     g3 = HiddenGroup (g, 2, 0, NULL);
17840     SqnPushButton (g3, "Desktop", ToolBtn15, bfp);
17841     b6 = SqnPushButton (g3, "On-Caller Tool", ToolBtnOncallerTool, bfp);
17842     AlignObjects (ALIGN_RIGHT, (HANDLE) b1, (HANDLE) b2, (HANDLE) b3, (HANDLE) b4, (HANDLE) b5, (HANDLE) b6, (HANDLE) b_top, NULL);
17843 
17844   }
17845   else
17846   {
17847     SqnPushButton (g, "Save", ToolBtn1, bfp);
17848     SqnPushButton (g, "Auto_Def", ToolBtn2, bfp);
17849     if (useTaxon) {
17850       /* SqnPushButton (g, "Tax_Fix", ToolBtn3, bfp); */
17851       SqnPushButton (g, "Tax_Fix/Clean_Up", ToolBtn3, bfp);
17852     }
17853     SqnPushButton (g, "Def_Org", ToolBtn4, bfp);
17854     SqnPushButton (g, "CDS", ToolBtn5, bfp);
17855     SqnPushButton (g, "rRNA", ToolBtn6, bfp);
17856     SqnPushButton (g, "mRna_CDS", ToolBtn7, bfp);
17857     SqnPushButton (g, "ORF_Find", ToolBtn8, bfp);
17858     SqnPushButton (g, "misc_feat", ToolBtn9, bfp);
17859     SqnPushButton (g, "SUC", ToolBtn10, bfp);
17860     SqnPushButton (g, "sub_affil", ToolBtn11, bfp);
17861     SqnPushButton (g, "sub_add", ToolBtn12, bfp);
17862     SqnPushButton (g, "cit-sub-upd", ToolBtn16, bfp);
17863     SqnPushButton (g, "Edit Pubs", ToolBtn13, bfp);
17864     SqnPushButton (g, "rem_prot_titles", ToolBtn17, bfp);
17865     SqnPushButton (g, "Validate", ToolBtn14, bfp);
17866     SqnPushButton (g, "Desktop", ToolBtn15, bfp);
17867   }
17868 }
17869 
MakeToolBarWindowBaseForm(BaseFormPtr bfp)17870 static void MakeToolBarWindowBaseForm (BaseFormPtr bfp)
17871 {
17872   SeqViewProcsPtr svpp;
17873   ForM         f;
17874 
17875   if (bfp == NULL) return;
17876   svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
17877   if (svpp != NULL) {
17878     svpp->createToolBar = BioseqViewFormToolBar;
17879   }
17880 
17881   f = ReplaceToolFormForBioseqView (bfp, BioseqViewFormToolBar);
17882   Show (f);
17883   Select (f);
17884 }
17885 
17886 
MakeToolBarWindow(IteM i)17887 static void MakeToolBarWindow (IteM i)
17888 
17889 {
17890   BaseFormPtr  bfp;
17891 
17892 #ifdef WIN_MAC
17893   bfp = currentFormDataPtr;
17894 #else
17895   bfp = GetObjectExtra (i);
17896 #endif
17897 
17898   MakeToolBarWindowBaseForm (bfp);
17899 }
17900 
17901 
WGSBtnRemoveGenomeProjectIds(ButtoN b)17902 static void WGSBtnRemoveGenomeProjectIds (ButtoN b)
17903 {
17904   BaseFormPtr  bfp;
17905   bfp = (BaseFormPtr) GetObjectExtra (b);
17906 
17907   RemoveGenomeProjectIdsBaseForm (bfp);
17908 }
17909 
17910 
WGSBtnAtccToCultureCollection(ButtoN b)17911 static void WGSBtnAtccToCultureCollection (ButtoN b)
17912 {
17913   BaseFormPtr  bfp;
17914   bfp = (BaseFormPtr) GetObjectExtra (b);
17915 
17916   AtccToCultureCollectionBaseForm (bfp);
17917 }
17918 
17919 
WGSBtnAddModToOrg(ButtoN b)17920 static void WGSBtnAddModToOrg (ButtoN b)
17921 {
17922   BaseFormPtr  bfp;
17923   bfp = (BaseFormPtr) GetObjectExtra (b);
17924 
17925   AddModToOrgBaseForm (bfp);
17926 }
17927 
WGSBtnUpdateECNumbers(ButtoN b)17928 static void WGSBtnUpdateECNumbers (ButtoN b)
17929 {
17930   BaseFormPtr  bfp;
17931   bfp = (BaseFormPtr) GetObjectExtra (b);
17932 
17933   UpdateECNumbersBaseForm (bfp);
17934 }
17935 
WGSBtnMegaReport(ButtoN b)17936 static void WGSBtnMegaReport (ButtoN b)
17937 {
17938   CreateReportWindow (eReportTypeMegaReport);
17939 }
17940 
WGSBtnOriginalSUC(ButtoN b)17941 static void WGSBtnOriginalSUC (ButtoN b)
17942 {
17943   BaseFormPtr  bfp;
17944   bfp = (BaseFormPtr) GetObjectExtra (b);
17945 
17946   SUCBaseForm (bfp, FALSE, TRUE, TRUE, FALSE);
17947 }
17948 
WGSBtnClickableSUC(ButtoN b)17949 static void WGSBtnClickableSUC (ButtoN b)
17950 {
17951   BaseFormPtr  bfp;
17952   bfp = (BaseFormPtr) GetObjectExtra (b);
17953 
17954   SUCBaseForm (bfp, FALSE, TRUE, FALSE, TRUE);
17955 }
17956 
WGSBtnPT_Cleanup(ButtoN b)17957 static void WGSBtnPT_Cleanup (ButtoN b)
17958 {
17959   BaseFormPtr  bfp;
17960   SeqEntryPtr  sep;
17961 
17962   bfp = (BaseFormPtr) GetObjectExtra (b);
17963   if (bfp == NULL) return;
17964 
17965   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
17966   if (sep == NULL) return;
17967 
17968   InstantiateProteinTitles (bfp->input_entityID, NULL);
17969 
17970   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
17971   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
17972   Update ();
17973 }
17974 
WBSBtnLaunchMacroEditor(ButtoN b)17975 static void WBSBtnLaunchMacroEditor (ButtoN b)
17976 {
17977   BaseFormPtr  bfp;
17978   bfp = (BaseFormPtr) GetObjectExtra (b);
17979 
17980   LaunchMacroEditor (bfp->input_entityID, NULL, NULL, NULL);
17981 }
17982 
17983 
CustomLaunchMacroTemplateEditor(ButtoN b)17984 static void CustomLaunchMacroTemplateEditor  (ButtoN b)
17985 {
17986   EditMacroTemplate();
17987 }
17988 
17989 
WGSBtnChangeTarget(ButtoN b)17990 static void WGSBtnChangeTarget (ButtoN b)
17991 {
17992   BaseFormPtr  bfp;
17993   bfp = (BaseFormPtr) GetObjectExtra (b);
17994 
17995   ChangeTargetBaseForm (bfp);
17996 }
17997 
WBSBtnRetranslateCodingRegions(ButtoN b)17998 static void WBSBtnRetranslateCodingRegions (ButtoN b)
17999 {
18000   BaseFormPtr  bfp;
18001   bfp = (BaseFormPtr) GetObjectExtra (b);
18002 
18003   RetranslateCdRegionsEx (bfp->input_entityID, TRUE, TRUE);
18004 }
18005 
WGSBtnAddComment(ButtoN b)18006 static void WGSBtnAddComment (ButtoN b)
18007 {
18008   BaseFormPtr  bfp;
18009   ObjMgrPtr      omp;
18010   ObjMgrTypePtr  omtp = NULL;
18011   ObjMgrProcPtr  ompp;
18012 
18013   bfp = (BaseFormPtr) GetObjectExtra (b);
18014   if (bfp == NULL) {
18015     return;
18016   }
18017 
18018   omp = ObjMgrGet ();
18019   if (omp == NULL) return;
18020   while ((omtp = ObjMgrTypeFindNext (omp, omtp)) != NULL) {
18021     if (omtp->datatype == OBJ_SEQDESC) {
18022       ompp = ObjMgrProcFindNext (omp, OMPROC_EDIT, omtp->datatype, 0, NULL);
18023       if (ompp != NULL) {
18024         ompp = NULL;
18025         while ((ompp = ObjMgrProcFindNext (omp, OMPROC_EDIT, omtp->datatype, 0, ompp)) != NULL) {
18026           if (ompp->subinputtype == Seq_descr_comment) {
18027             NewDescriptorMenuFunc (ompp, bfp, Seq_descr_comment);
18028             return;
18029           }
18030         }
18031       }
18032     }
18033   }
18034 }
18035 
18036 
RemoveAllFeaturesCallback(SeqFeatPtr sfp,Pointer data)18037 static void RemoveAllFeaturesCallback (SeqFeatPtr sfp, Pointer data)
18038 {
18039   BioseqPtr bsp;
18040 
18041   if (sfp != NULL) {
18042     sfp->idx.deleteme = TRUE;
18043     if (sfp->product != NULL) {
18044       bsp = BioseqFindFromSeqLoc (sfp->product);
18045       if (bsp != NULL) {
18046         bsp->idx.deleteme = TRUE;
18047       }
18048     }
18049   }
18050 }
18051 
18052 
WGSBtnRemoveAllFeatures(ButtoN b)18053 static void WGSBtnRemoveAllFeatures (ButtoN b)
18054 {
18055   BaseFormPtr bfp;
18056   SeqEntryPtr sep;
18057 
18058   bfp = (BaseFormPtr) GetObjectExtra (b);
18059   if (bfp == NULL) {
18060     return;
18061   }
18062 
18063   if (Message (MSG_OKC, "Are you sure?  This will remove all features, all protein sequences, and all mRNA product sequences.") != ANS_OK) {
18064     return;
18065   }
18066 
18067   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
18068   VisitFeaturesInSep (sep, NULL, RemoveAllFeaturesCallback);
18069 
18070   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
18071   RemoveOrphanProteins (bfp->input_entityID, sep);
18072   RenormalizeNucProtSets (sep, TRUE);
18073   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
18074   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
18075   Update ();
18076 }
18077 
BioseqViewFormWGSToolBar(GrouP h)18078 extern void BioseqViewFormWGSToolBar (GrouP h)
18079 
18080 {
18081   BaseFormPtr  bfp;
18082   GrouP        g, g2, g3;
18083   ButtoN       b1, b2, b_top;
18084 
18085   bfp = (BaseFormPtr) GetObjectExtra (h);
18086   if (bfp == NULL) return;
18087   g = HiddenGroup (h, 1, 0, NULL);
18088 
18089   b_top = SqnPushButton (g, "Remove GPID", WGSBtnRemoveGenomeProjectIds, bfp);
18090   SqnPushButton (g, "Parse ATCC", WGSBtnAtccToCultureCollection, bfp);
18091   SqnPushButton (g, "Append to Organism", WGSBtnAddModToOrg, bfp);
18092   if (useTaxon) {
18093     SqnPushButton (g, "Tax_Fix/Clean_Up", ToolBtn3, bfp);
18094   }
18095   SqnPushButton (g, "EC Number Cleanup", WGSBtnUpdateECNumbers, bfp);
18096   SqnPushButton (g, "Add Comment", WGSBtnAddComment, bfp);
18097 
18098   g3 = HiddenGroup (g, 2, 0, NULL);
18099   SqnPushButton (g3, "SUC", WGSBtnOriginalSUC, bfp);
18100   b2 = SqnPushButton (g3, "cSUC", WGSBtnClickableSUC, bfp);
18101 
18102   SqnPushButton (g, "Macro Editor", WBSBtnLaunchMacroEditor, bfp);
18103   SqnPushButton (g, "Retranslate CDS", WBSBtnRetranslateCodingRegions, bfp);
18104   SqnPushButton (g, "Remove DefLines", RemoveDefLinesToolBtn, bfp);
18105   g2 = HiddenGroup (g, 2, 0, NULL);
18106   SqnPushButton (g2, "Trim Ns", TrimNsFromNucsToolBtn, bfp);
18107   SqnPushButton (g2, "Apply Source Qual", ApplySourceQualToolBtn, bfp);
18108   g2 = HiddenGroup (g, 2, 0, NULL);
18109   SqnPushButton (g2, "Find ASN.1", FindStringProcToolBtn, bfp);
18110   b1 = SqnPushButton (g2, "Find FF", FindFlatfileProcToolBtn, bfp);
18111   AlignObjects (ALIGN_RIGHT, (HANDLE) b_top, (HANDLE) b1, (HANDLE) b2, NULL);
18112 
18113   SqnPushButton (g, "Select Target", WGSBtnChangeTarget, bfp);
18114   SqnPushButton (g, "Remove All Features", WGSBtnRemoveAllFeatures, bfp);
18115   SqnPushButton (g, "Group Explode", GroupExplodeToolBtn, bfp);
18116   SqnPushButton (g, "cit-sub-upd", ToolBtn16, bfp);
18117   SqnPushButton (g, "PT_Cleanup", WGSBtnPT_Cleanup, bfp);
18118   SqnPushButton (g, "rem_prot_titles", ToolBtn17, bfp);
18119   SqnPushButton (g, "MegaReport", WGSBtnMegaReport, bfp);
18120   SqnPushButton (g, "Validate", ToolBtn14, bfp);
18121   SqnPushButton (g, "Desktop", ToolBtn15, bfp);
18122 
18123 }
18124 
MakeWGSToolBar(IteM i)18125 static void MakeWGSToolBar (IteM i)
18126 
18127 {
18128   BaseFormPtr  bfp;
18129   ForM         f;
18130   SeqViewProcsPtr svpp;
18131 
18132 #ifdef WIN_MAC
18133   bfp = currentFormDataPtr;
18134 #else
18135   bfp = GetObjectExtra (i);
18136 #endif
18137   if (bfp == NULL) return;
18138   svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
18139   if (svpp != NULL) {
18140     svpp->createToolBar = BioseqViewFormWGSToolBar;
18141   }
18142   f = ReplaceToolFormForBioseqView (bfp, BioseqViewFormWGSToolBar);
18143   Show (f);
18144   Select (f);
18145 }
18146 
18147 
ApplyNamedRNAButton(ButtoN b,CharPtr rnaName)18148 static void ApplyNamedRNAButton (ButtoN b, CharPtr rnaName)
18149 {
18150   BaseFormPtr  bfp;
18151 
18152   bfp = (BaseFormPtr) GetObjectExtra (b);
18153   if (bfp == NULL) return;
18154 
18155   ApplyNamedRNABaseForm (bfp, rnaName);
18156 }
18157 
18158 
Add16SBtn(ButtoN b)18159 static void Add16SBtn (ButtoN b)
18160 {
18161   ApplyNamedRNAButton (b, "16S ribosomal RNA");
18162 }
18163 
18164 
Add18SBtn(ButtoN b)18165 static void Add18SBtn (ButtoN b)
18166 {
18167   ApplyNamedRNAButton (b, "18S ribosomal RNA");
18168 }
18169 
18170 
Add23SBtn(ButtoN b)18171 static void Add23SBtn (ButtoN b)
18172 {
18173   ApplyNamedRNAButton (b, "23S ribosomal RNA");
18174 }
18175 
18176 
18177 #define FIX_AUTHOR_NAME_ORDER	          1
18178 #define FIX_PUB_AUTHOR_CAPITALIZATION	  2
18179 #define FIX_PUB_TITLE_CAPITALIZATION	  4
18180 #define FIX_PUB_AFFIL_CAPITALIZATION	  8
18181 #define FIX_SELECTED			              16
18182 #define FIX_ALL                         32
18183 #define STRIP_AUTHOR_SUFFIX             64
18184 #define FIX_PUB_SWAP_NAME_CONSORTIUM    128
18185 #define TRUNCATE_AUTHOR_MIDDLE_INITIALS 256
18186 #define FIX_PUB_AFFIL_COUNTRY_CAPITALIZATION 512
18187 
18188 static void FixPubs (Uint2 entityID, Int4 iType, StringConstraintXPtr author_scp);
18189 
StripAuthorSuffixBtn(ButtoN b)18190 static void StripAuthorSuffixBtn (ButtoN b)
18191 {
18192   BaseFormPtr bfp;
18193 
18194   bfp = GetObjectExtra (b);
18195 
18196   if (bfp == NULL) return;
18197   FixPubs (bfp->input_entityID, STRIP_AUTHOR_SUFFIX, NULL);
18198 }
18199 
18200 
EditFeatureLocationBtn(ButtoN b)18201 static void EditFeatureLocationBtn (ButtoN b)
18202 {
18203   BaseFormPtr bfp;
18204 
18205   bfp = GetObjectExtra (b);
18206 
18207   if (bfp == NULL) return;
18208   FeatureEditorBaseForm (bfp, FEAT_ED_PARTIAL);
18209 }
18210 
18211 
LowercaseQualsBtn(ButtoN b)18212 static void LowercaseQualsBtn (ButtoN b)
18213 {
18214   BaseFormPtr bfp;
18215 
18216   bfp = GetObjectExtra (b);
18217 
18218   if (bfp == NULL) return;
18219   ChangeQualifierCaseBaseForm (bfp);
18220 }
18221 
18222 
ToolbarBtn(ButtoN b)18223 static void ToolbarBtn (ButtoN b)
18224 {
18225   BaseFormPtr bfp;
18226 
18227   bfp = GetObjectExtra (b);
18228 
18229   if (bfp == NULL) return;
18230   MakeToolBarWindowBaseForm (bfp);
18231 }
18232 
18233 
RemoveUnpubBtn(ButtoN b)18234 static void RemoveUnpubBtn (ButtoN b)
18235 {
18236   BaseFormPtr bfp;
18237 
18238   bfp = GetObjectExtra (b);
18239 
18240   if (bfp == NULL) return;
18241   RemoveUnpublishedPublicationsBaseForm (bfp);
18242 }
18243 
18244 
SourceFileBtn(ButtoN b)18245 static void SourceFileBtn (ButtoN b)
18246 {
18247   BaseFormPtr bfp;
18248 
18249   bfp = GetObjectExtra (b);
18250 
18251   if (bfp == NULL) return;
18252   LoadOrganismModifierTableBaseForm (bfp, FALSE);
18253 }
18254 
18255 
RemoveAllSourceNotesBtn(ButtoN b)18256 static void RemoveAllSourceNotesBtn (ButtoN b)
18257 {
18258   BaseFormPtr bfp;
18259 
18260   bfp = GetObjectExtra (b);
18261 
18262   if (bfp == NULL) return;
18263 
18264   RemoveAllSourceNoteBaseForm (bfp);
18265 }
18266 
18267 
AddIsolSrcBtn(ButtoN b)18268 static void AddIsolSrcBtn (ButtoN b)
18269 {
18270   BaseFormPtr bfp;
18271 
18272   bfp = GetObjectExtra (b);
18273 
18274   if (bfp == NULL) return;
18275 
18276   ApplyIsolationSourceBaseForm (bfp);
18277 }
18278 
18279 
StrainToSpBtn(ButtoN b)18280 static void StrainToSpBtn (ButtoN b)
18281 {
18282   BaseFormPtr bfp;
18283   SeqEntryPtr sep;
18284   ConvertActionPtr convert;
18285   AECRActionPtr aecr;
18286   ValNodePtr    macro;
18287   SourceQualPairPtr pair;
18288   SourceConstraintPtr constraint;
18289 
18290   bfp = GetObjectExtra (b);
18291 
18292   if (bfp == NULL) {
18293     return;
18294   }
18295 
18296   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
18297   if (sep == NULL) {
18298     return;
18299   }
18300 
18301   pair = SourceQualPairNew ();
18302   pair->field_from = Source_qual_strain;
18303   pair->field_to = Source_qual_taxname;
18304 
18305   convert = ConvertActionNew ();
18306   convert->fields = ValNodeNew (NULL);
18307   convert->fields->choice = FieldPairType_source_qual;
18308   convert->fields->data.ptrvalue = pair;
18309   convert->existing_text = ExistingTextOption_append_space;
18310   convert->keep_original = TRUE;
18311 
18312   aecr = AECRActionNew ();
18313   aecr->action = ValNodeNew (NULL);
18314   aecr->action->choice = ActionChoice_convert;
18315   aecr->action->data.ptrvalue = convert;
18316 
18317   constraint = SourceConstraintNew ();
18318   constraint->field1 = ValNodeNew (NULL);
18319   constraint->field1->choice = SourceQualChoice_textqual;
18320   constraint->field1->data.intvalue = Source_qual_taxname;
18321   constraint->constraint = StringConstraintNew ();
18322   constraint->constraint->match_location = String_location_ends;
18323   constraint->constraint->match_text = StringSave (" sp.");
18324   aecr->constraint = ValNodeNew (NULL);
18325   aecr->constraint->choice = ConstraintChoice_source;
18326   aecr->constraint->data.ptrvalue = constraint;
18327   macro = ValNodeNew (NULL);
18328   macro->choice = MacroActionChoice_aecr;
18329   macro->data.ptrvalue = aecr;
18330 
18331   ApplyMacroToSeqEntry (sep, macro);
18332 
18333   macro = MacroActionChoiceFree(macro);
18334 }
18335 
18336 #if defined(OS_UNIX) || defined(OS_MSWIN)
RevComp16SBtn(ButtoN b)18337 static void RevComp16SBtn (ButtoN b)
18338 {
18339   BaseFormPtr   bfp;
18340 
18341   bfp = GetObjectExtra (b);
18342   if (bfp == NULL) return;
18343 
18344   CorrectRNAStrandednessForEntityID (bfp->input_entityID, TRUE);
18345 }
18346 #endif
18347 
StructuredCommentKeywordsBtn(ButtoN b)18348 static void StructuredCommentKeywordsBtn (ButtoN b)
18349 {
18350   BaseFormPtr   bfp;
18351 
18352   bfp = GetObjectExtra (b);
18353   if (bfp == NULL) return;
18354 
18355   AddStructuredCommentKeywords (bfp->input_entityID);
18356 }
18357 
18358 
18359 
EditCDSQualBtn(ButtoN b)18360 static void EditCDSQualBtn (ButtoN b)
18361 {
18362   BaseFormPtr   bfp;
18363 
18364   bfp = GetObjectExtra (b);
18365   if (bfp == NULL) return;
18366 
18367   SingleAECRMacroAction (bfp->input_entityID, indexerVersion, ActionChoice_edit, FieldType_cds_gene_prot);
18368 }
18369 
18370 
AddRnaBtn(ButtoN b)18371 static void AddRnaBtn (ButtoN b)
18372 {
18373   BaseFormPtr   bfp;
18374 
18375   bfp = GetObjectExtra (b);
18376   if (bfp == NULL) return;
18377 
18378   CommonApplyToAllProc (bfp, ADD_RRNA);
18379 }
18380 
18381 
CustomClearBtn(ButtoN b)18382 static void CustomClearBtn (ButtoN b)
18383 {
18384   BaseFormPtr   bfp;
18385 
18386   bfp = GetObjectExtra (b);
18387   if (bfp == NULL) return;
18388 
18389   ClearSelectedItem (bfp);
18390 }
18391 
18392 
CustomBadQualsCommonBtn(ButtoN b,Boolean wrong,Boolean illegal,Boolean move_to_note)18393 static void CustomBadQualsCommonBtn (ButtoN b, Boolean wrong, Boolean illegal, Boolean move_to_note)
18394 {
18395   BaseFormPtr   bfp;
18396 
18397   bfp = GetObjectExtra (b);
18398   if (bfp == NULL) return;
18399 
18400   RemoveBadQualsCommon (bfp->input_entityID, wrong, illegal, move_to_note);
18401 }
18402 
18403 
CustomRemoveIllegalQuals(ButtoN b)18404 static void CustomRemoveIllegalQuals (ButtoN b)
18405 {
18406   CustomBadQualsCommonBtn (b, FALSE, TRUE, FALSE);
18407 }
18408 
18409 
CustomRemoveWrongQuals(ButtoN b)18410 static void CustomRemoveWrongQuals (ButtoN b)
18411 {
18412   CustomBadQualsCommonBtn (b, TRUE, FALSE, FALSE);
18413 }
18414 
18415 
CustomMoveIllegalQuals(ButtoN b)18416 static void CustomMoveIllegalQuals (ButtoN b)
18417 {
18418   CustomBadQualsCommonBtn (b, FALSE, TRUE, TRUE);
18419 }
18420 
18421 
CustomMoveWrongQuals(ButtoN b)18422 static void CustomMoveWrongQuals (ButtoN b)
18423 {
18424   CustomBadQualsCommonBtn (b, TRUE, FALSE, TRUE);
18425 }
18426 
18427 
CustomSegregate(ButtoN b)18428 static void CustomSegregate (ButtoN b)
18429 {
18430   BaseFormPtr bfp;
18431 
18432   bfp = GetObjectExtra (b);
18433   if (bfp == NULL) return;
18434 
18435   SegregateBioseqSetEntityID (bfp->input_entityID);
18436 }
18437 
18438 
SegregateByPlantGroupItem(IteM i)18439 static void SegregateByPlantGroupItem (IteM i)
18440 {
18441   BaseFormPtr bfp;
18442   SeqEntryPtr sep;
18443 
18444 #ifdef WIN_MAC
18445   bfp = currentFormDataPtr;
18446 #else
18447   bfp = GetObjectExtra (i);
18448 #endif
18449   if (bfp == NULL) return;
18450 
18451   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
18452   SegregateSetsByPlantGroup (sep);
18453   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
18454   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
18455 }
18456 
18457 
SegregateByFungusGroupItem(IteM i)18458 static void SegregateByFungusGroupItem (IteM i)
18459 {
18460   BaseFormPtr bfp;
18461   SeqEntryPtr sep;
18462 
18463 #ifdef WIN_MAC
18464   bfp = currentFormDataPtr;
18465 #else
18466   bfp = GetObjectExtra (i);
18467 #endif
18468   if (bfp == NULL) return;
18469 
18470   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
18471   SegregateSetsByFungusGroup (sep);
18472   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
18473   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
18474 }
18475 
18476 
18477 static void FixPubCapsAuthor (ButtoN b);
18478 static void FixPubCapsAffil (ButtoN b);
18479 static void FixPubCapsTitle (ButtoN b);
18480 
DiscrepancyReportBtn(ButtoN b)18481 static void DiscrepancyReportBtn (ButtoN b)
18482 {
18483   CreateReportWindow (eReportTypeDiscrepancy);
18484 }
18485 
18486 
InsertGenbankSet(ButtoN b)18487 static void InsertGenbankSet (ButtoN b)
18488 {
18489   BaseFormPtr bfp;
18490 
18491   bfp = GetObjectExtra (b);
18492   if (bfp == NULL) return;
18493 
18494   InsertSetEntityID (bfp->input_entityID, BioseqseqSet_class_genbank);
18495 }
18496 
18497 
CustomCorrectGene(ButtoN b)18498 static void CustomCorrectGene (ButtoN b)
18499 {
18500   BaseFormPtr bfp;
18501 
18502   bfp = GetObjectExtra (b);
18503   if (bfp == NULL) return;
18504 
18505   CorrectGenesBaseForm (bfp);
18506 }
18507 
18508 
AddOtherFeatureBtn(ButtoN b)18509 static void AddOtherFeatureBtn (ButtoN b)
18510 {
18511   BaseFormPtr bfp;
18512 
18513   bfp = GetObjectExtra (b);
18514   if (bfp == NULL) return;
18515   CommonApplyToAllProc (bfp, ADD_IMP);
18516 }
18517 
18518 
ParseDeflineBtn(ButtoN b)18519 static void ParseDeflineBtn (ButtoN b)
18520 {
18521   BaseFormPtr bfp;
18522   ForM         f;
18523   ParseActionPtr parse;
18524 
18525   bfp = GetObjectExtra (b);
18526   if (bfp == NULL) return;
18527 
18528   f = SingleParseAction (bfp->input_entityID);
18529   if (f != NULL) {
18530     /* create parse action with preselected fields */
18531     parse = ParseActionNew ();
18532     /* choose defline as source */
18533     parse->src = ValNodeNew (NULL);
18534     parse->src->choice = ParseSrc_defline;
18535     /* choose source qualifiers as dest */
18536     parse->dest = ValNodeNew (NULL);
18537     parse->dest->choice = ParseDest_org;
18538     PointerToForm (f, parse);
18539     parse = ParseActionFree (parse);
18540     Show (f);
18541   }
18542 }
18543 
18544 
TaxFixToolBtn(ButtoN b)18545 static void TaxFixToolBtn (ButtoN b)
18546 {
18547   BaseFormPtr bfp;
18548 
18549   bfp = GetObjectExtra (b);
18550   if (bfp == NULL) return;
18551   TaxFixToolBaseForm (bfp);
18552 }
18553 
18554 
EditRnaQualBtn(ButtoN b)18555 static void EditRnaQualBtn (ButtoN b)
18556 {
18557   BaseFormPtr bfp;
18558 
18559   bfp = GetObjectExtra (b);
18560   if (bfp == NULL) return;
18561 
18562   SingleAECRMacroAction (bfp->input_entityID, TRUE, ActionChoice_edit, FieldType_rna_field);
18563 }
18564 
18565 
EditStructFieldBtn(ButtoN b)18566 static void EditStructFieldBtn (ButtoN b)
18567 {
18568   BaseFormPtr bfp;
18569 
18570   bfp = GetObjectExtra (b);
18571   if (bfp == NULL) return;
18572 
18573   SingleAECRMacroAction (bfp->input_entityID, TRUE, ActionChoice_edit, FieldType_struc_comment_field);
18574 }
18575 
18576 
LoadStructCommBtn(ButtoN b)18577 static void LoadStructCommBtn (ButtoN b)
18578 {
18579   BaseFormPtr bfp;
18580 
18581   bfp = GetObjectExtra (b);
18582   if (bfp == NULL) return;
18583 
18584   CreateStructuredCommentsBaseForm (bfp);
18585 }
18586 
18587 
AddGPIDBtn(ButtoN b)18588 static void AddGPIDBtn (ButtoN b)
18589 {
18590   BaseFormPtr   bfp;
18591   ObjMgrPtr     omp;
18592   ObjMgrProcPtr ompp;
18593 
18594   bfp = GetObjectExtra (b);
18595   if (bfp == NULL) return;
18596 
18597   omp = ObjMgrGet ();
18598   if (omp == NULL) return;
18599   ompp = ObjMgrProcFindNext (omp, OMPROC_EDIT, OBJ_SEQDESC, 0, NULL);
18600   while (ompp != NULL
18601          && (ompp->subinputtype != Seq_descr_user
18602              || StringCmp (ompp->proclabel, "GenomeProjectsDB") != 0)) {
18603     ompp = ObjMgrProcFindNext (omp, OMPROC_EDIT, OBJ_SEQDESC, 0, ompp);
18604   }
18605 
18606   if (ompp != NULL) {
18607     NewDescriptorMenuFuncEx (ompp, bfp, Seq_descr_user, "GenomeProjectsDB");
18608   }
18609 }
18610 
18611 
BulkEditSrcBtn(ButtoN b)18612 static void BulkEditSrcBtn (ButtoN b)
18613 {
18614   BaseFormPtr bfp;
18615 
18616   bfp = GetObjectExtra (b);
18617   if (bfp == NULL) return;
18618 
18619   BulkEditSourceBaseForm (bfp);
18620 }
18621 
18622 
RemoveStructCommCallback(SeqDescPtr sdp,Pointer data)18623 static void RemoveStructCommCallback (SeqDescPtr sdp, Pointer data)
18624 {
18625   UserObjectPtr uop;
18626   ObjValNodePtr ovn;
18627 
18628   if (sdp == NULL || sdp->choice != Seq_descr_user
18629       || (uop = (UserObjectPtr) sdp->data.ptrvalue) == NULL
18630       || uop->type == NULL
18631       || StringICmp (uop->type->str, "StructuredComment") != 0
18632       || sdp->extended == 0)
18633   {
18634     return;
18635   }
18636   ovn = (ObjValNodePtr) sdp;
18637   ovn->idx.deleteme = TRUE;
18638 }
18639 
18640 
RemoveStructComm(Uint2 entityID)18641 static void RemoveStructComm (Uint2 entityID)
18642 {
18643   SeqEntryPtr sep;
18644 
18645   sep = GetTopSeqEntryForEntityID (entityID);
18646   VisitDescriptorsInSep (sep, NULL, RemoveStructCommCallback);
18647   DeleteMarkedObjects (entityID, 0, NULL);
18648   ObjMgrSetDirtyFlag (entityID, TRUE);
18649   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
18650 }
18651 
18652 
RemoveStructCommMenuItem(IteM i)18653 static void RemoveStructCommMenuItem (IteM i)
18654 {
18655   BaseFormPtr bfp;
18656 
18657 #ifdef WIN_MAC
18658   bfp = currentFormDataPtr;
18659 #else
18660   bfp = GetObjectExtra (i);
18661 #endif
18662 
18663   if (bfp == NULL) return;
18664   RemoveStructComm (bfp->input_entityID);
18665 }
18666 
18667 
RemoveStructCommBtn(ButtoN b)18668 static void RemoveStructCommBtn (ButtoN b)
18669 {
18670   BaseFormPtr bfp;
18671 
18672   bfp = GetObjectExtra (b);
18673   if (bfp == NULL) return;
18674 
18675   RemoveStructComm (bfp->input_entityID);
18676 }
18677 
18678 
FindFrameShiftBtn(ButtoN b)18679 static void FindFrameShiftBtn (ButtoN b)
18680 {
18681   BaseFormPtr bfp;
18682 
18683   bfp = GetObjectExtra (b);
18684   if (bfp == NULL) return;
18685 
18686   FrameShiftFinderEntityID (bfp->input_entityID, FALSE);
18687 }
18688 
18689 
FindFrameShiftClipBtn(ButtoN b)18690 static void FindFrameShiftClipBtn (ButtoN b)
18691 {
18692   BaseFormPtr bfp;
18693 
18694   bfp = GetObjectExtra (b);
18695   if (bfp == NULL) return;
18696 
18697   FrameShiftFinderEntityID (bfp->input_entityID, TRUE);
18698 }
18699 
18700 
AddGnmAsmbCmt(ButtoN b)18701 static void AddGnmAsmbCmt(ButtoN b)
18702 {
18703   BaseFormPtr bfp;
18704 
18705   bfp = GetObjectExtra (b);
18706   if (bfp == NULL) return;
18707 
18708   ApplyFormattedStructuredCommentBaseForm (bfp, "Genome-Assembly");
18709 }
18710 
18711 
RetranslateCDSNoStp(ButtoN b)18712 static void RetranslateCDSNoStp (ButtoN b)
18713 {
18714   BaseFormPtr bfp;
18715 
18716   bfp = GetObjectExtra (b);
18717   if (bfp == NULL) return;
18718   RetranslateCdRegionsChooseFrameWithNoStopForEntityID (bfp->input_entityID);
18719 }
18720 
18721 
NewEditMolInfoBtn(ButtoN b)18722 static void NewEditMolInfoBtn (ButtoN b)
18723 {
18724   BaseFormPtr bfp;
18725 
18726   bfp = GetObjectExtra (b);
18727   if (bfp == NULL) return;
18728   NewMolInfoFieldsBaseForm (bfp, TRUE);
18729 }
18730 
18731 
SequesterBtn(ButtoN b)18732 static void SequesterBtn (ButtoN b)
18733 {
18734   BaseFormPtr bfp;
18735 
18736   bfp = GetObjectExtra (b);
18737   if (bfp == NULL) return;
18738   SequesterSequencesEntityID (bfp->input_entityID);
18739 }
18740 
18741 
ViewSortedProBtn(ButtoN b)18742 static void ViewSortedProBtn (ButtoN b)
18743 {
18744   BaseFormPtr bfp;
18745   SeqEntryPtr sep;
18746 
18747   bfp = GetObjectExtra (b);
18748   if (bfp == NULL) return;
18749   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
18750   if (sep == NULL) return;
18751   ViewSortedProteins(sep);
18752 }
18753 
18754 
UpdateSingleSeqClipBtn(ButtoN b)18755 static void UpdateSingleSeqClipBtn (ButtoN b)
18756 {
18757   BaseFormPtr bfp;
18758 
18759   bfp = GetObjectExtra (b);
18760   if (bfp == NULL) return;
18761   TestUpdateSequenceBaseForm (bfp, TRUE, TRUE, TRUE);
18762 }
18763 
18764 
UpdateMultSeqsClipBtn(ButtoN b)18765 static void UpdateMultSeqsClipBtn (ButtoN b)
18766 {
18767   BaseFormPtr bfp;
18768 
18769   bfp = GetObjectExtra (b);
18770   if (bfp == NULL) return;
18771   TestUpdateSequenceSetBaseForm (bfp, TRUE, TRUE, TRUE);
18772 }
18773 
18774 static void RevAuthNamesBtn (ButtoN b);
18775 
18776 
ReorderStructFieldsBtn(ButtoN b)18777 static void ReorderStructFieldsBtn (ButtoN b)
18778 {
18779   BaseFormPtr bfp;
18780   SeqEntryPtr sep;
18781 
18782   bfp = GetObjectExtra (b);
18783   if (bfp == NULL) return;
18784   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
18785   if (sep == NULL) return;
18786 
18787   VisitDescriptorsInSep (sep, NULL, DoReorderStructuredCommentFields);
18788 }
18789 
18790 
ExtendPartialEndsBtn(ButtoN b)18791 static void ExtendPartialEndsBtn  (ButtoN b)
18792 {
18793   BaseFormPtr bfp;
18794 
18795   bfp = GetObjectExtra (b);
18796   if (bfp == NULL) return;
18797   ExtendPartialFeaturesToEndsForEntityID (bfp->input_entityID);
18798 }
18799 
18800 
RemoveFeatsBtn(ButtoN b)18801 static void RemoveFeatsBtn (ButtoN b)
18802 {
18803   BaseFormPtr bfp;
18804 
18805   bfp = GetObjectExtra (b);
18806   if (bfp == NULL) return;
18807   FeatureRemoveOrConvertBaseForm (bfp, FEATURE_REMOVE);
18808 }
18809 
18810 
ExportTableBtn(ButtoN b)18811 static void ExportTableBtn (ButtoN b)
18812 {
18813   ButtonOrMenuButtonTemplate (b, ExportQualifiersBaseForm);
18814 }
18815 
18816 
AddTranslExceptWithCommentBtn(ButtoN b)18817 static void AddTranslExceptWithCommentBtn (ButtoN b)
18818 {
18819   ButtonOrMenuButtonTemplate (b, AddTranslExceptWithCommentBaseForm);
18820 }
18821 
18822 
RmTextInsideStringBtn(ButtoN b)18823 static void RmTextInsideStringBtn (ButtoN b)
18824 {
18825   ButtonOrMenuButtonTemplate (b, RemoveTextInsideStringBaseForm);
18826 }
18827 
18828 
RmTextOutsideStringBtn(ButtoN b)18829 static void RmTextOutsideStringBtn (ButtoN b)
18830 {
18831   ButtonOrMenuButtonTemplate (b, RemoveTextOutsideStringBaseForm);
18832 }
18833 
18834 
18835 static void LabelNewRNAsBaseForm (BaseFormPtr bfp);
18836 
CustomLabelrRNAs(ButtoN b)18837 static void CustomLabelrRNAs (ButtoN b)
18838 {
18839   ButtonOrMenuButtonTemplate (b, LabelNewRNAsBaseForm);
18840 }
18841 
18842 
ExtPartialsConstraintBtn(ButtoN b)18843 static void ExtPartialsConstraintBtn (ButtoN b)
18844 {
18845   ButtonOrMenuButtonTemplate (b, ExtendPartialFeaturesWithConstraintBaseForm);
18846 }
18847 
18848 
BulkEditCDSBtn(ButtoN b)18849 static void BulkEditCDSBtn (ButtoN b)
18850 {
18851   ButtonOrMenuButtonTemplate (b, BulkEditCDSBaseForm);
18852 }
18853 
18854 
18855 typedef struct namedbutton {
18856   CharPtr name;
18857   BtnActnProc proc;
18858 } NamedButtonData, PNTR NamedButtonPtr;
18859 
18860 
18861 static const NamedButtonData CustomButtons[] = {
18862   { "Add 16S", Add16SBtn},
18863   { "Add 18S", Add18SBtn},
18864   { "Add 23S", Add23SBtn},
18865   { "Add CDS", ApplyCDSBtn},
18866   { "Add Set", AddSetToolBtn } ,
18867   { "Add G Set", InsertGenbankSet },
18868   { "Add Gnm Asmb Cmt", AddGnmAsmbCmt },
18869   { "Add Comment", WGSBtnAddComment } ,
18870   { "Add Isol Source", AddIsolSrcBtn } ,
18871   { "Add Other Feature", AddOtherFeatureBtn } ,
18872   { "Add RNA", AddRnaBtn } ,
18873   { "Add GPID", AddGPIDBtn },
18874   { "Add Tsl Excepts Cmt", AddTranslExceptWithCommentBtn },
18875   { "Ad_ID", AutoDefStrainToolBtn } ,
18876   { "Ad_misc", AutoDefMiscFeatToolBtn } ,
18877   { "Append to Organism", WGSBtnAddModToOrg } ,
18878   { "Apply Source Qual", ApplySourceQualToolBtn } ,
18879   { "Autofix", RunAutoFixScriptToolBtn } ,
18880   { "Auto_Def", AutoDefToolBtn } ,
18881   { "Auto_Def Options", AutoDefOptionsToolBtn } ,
18882   { "Bulk Edit CDS", BulkEditCDSBtn },
18883   { "Bulk Edit Source", BulkEditSrcBtn } ,
18884   { "CDS", ToolBtn5 } ,
18885   { "cit-sub-upd", ToolBtn16 } ,
18886   { "Clear", CustomClearBtn } ,
18887   { "Convert CDS to MiscFeat", ConvertCDSButton } ,
18888   { "Correct Gene for CDS", CustomCorrectGene } ,
18889   { "cSUC", WGSBtnClickableSUC } ,
18890   { "Def_Org", ToolBtn4 } ,
18891   { "Desktop", ToolBtn15 } ,
18892   { "DiscrepancyReport", DiscrepancyReportBtn } ,
18893   { "EC Number Cleanup", WGSBtnUpdateECNumbers } ,
18894   { "Edit CDS qual", EditCDSQualBtn } ,
18895   { "Edit Location", EditFeatureLocationBtn } ,
18896   { "Edit Mol Info", NewEditMolInfoBtn } ,
18897   { "Edit Pubs", ToolBtn13 } ,
18898   { "Edit RNA Qual", EditRnaQualBtn } ,
18899   { "Edit StructField", EditStructFieldBtn },
18900   { "Export Table", ExportTableBtn },
18901   { "Extend Partials Ends", ExtendPartialEndsBtn } ,
18902   { "ExtPartialsConstraint", ExtPartialsConstraintBtn } ,
18903   { "Find ASN.1", FindStringProcToolBtn } ,
18904   { "Find FF", FindFlatfileProcToolBtn } ,
18905   { "Find Frameshift", FindFrameShiftBtn } ,
18906   { "Find Frameshift Clip", FindFrameShiftClipBtn } ,
18907   { "Fix Caps", FixCapitalizationToolBtn } ,
18908   { "Fix Caps Authors", FixPubCapsAuthor } ,
18909   { "Fix Caps Affil", FixPubCapsAffil } ,
18910   { "Fix Caps Titles", FixPubCapsTitle } ,
18911   { "Fix Local IDs", ResolveExistingLocalIDsToolBtn } ,
18912   { "gene", ToolBtnGene } ,
18913   { "Group Explode", GroupExplodeToolBtn } ,
18914   { "IllegalQuals to Note", CustomMoveIllegalQuals },
18915   { "Label rRNAs", CustomLabelrRNAs },
18916   { "Load StructComm", LoadStructCommBtn } ,
18917   { "Load Tax Acc", LoadTaxConsultBtn } ,
18918   { "Load Tax Name", LoadTaxTableReaderBtn },
18919   { "LC Quals", LowercaseQualsBtn },
18920   { "Local ID->Src", ParseLocalIDToSourceQual } ,
18921   { "Macro Editor", WBSBtnLaunchMacroEditor } ,
18922   { "Macro Template Editor", CustomLaunchMacroTemplateEditor } ,
18923   { "MegaReport", WGSBtnMegaReport } ,
18924   { "misc_feat", ToolBtn9 } ,
18925   { "mRna_CDS", ToolBtn7 } ,
18926   { "On-Caller Tool", ToolBtnOncallerTool } ,
18927   { "ORF_Find", ToolBtn8 } ,
18928   { "Parse ATCC", WGSBtnAtccToCultureCollection } ,
18929   { "Parse Defline", ParseDeflineBtn } ,
18930   { "PT_Cleanup", WGSBtnPT_Cleanup } ,
18931   { "RemoveStructComm", RemoveStructCommBtn },
18932   { "Remove All Features", WGSBtnRemoveAllFeatures } ,
18933   { "Remove DefLines", RemoveDefLinesToolBtn } ,
18934   { "Remove Dup Feats", NewRemoveDuplicateFeatsButton } ,
18935   { "Remove GPID", WGSBtnRemoveGenomeProjectIds } ,
18936   { "Remove Illegal Quals", CustomRemoveIllegalQuals },
18937   { "Remove Select Feats", RemoveFeatsBtn } ,
18938   { "Remove Seqs", RemoveSequencesFromRecordBtn },
18939   { "Remove SrcNotes", RemoveAllSourceNotesBtn } ,
18940   { "Remove Unpub", RemoveUnpubBtn },
18941   { "Remove Wrong Quals", CustomRemoveWrongQuals },
18942   { "rem_prot_titles", ToolBtn17 } ,
18943   { "Reorder Strct Cmt", ReorderStructFieldsBtn } ,
18944   { "Retranslate CDS", WBSBtnRetranslateCodingRegions } ,
18945   { "Retranslate CDS NoStp", RetranslateCDSNoStp } ,
18946 #if defined(OS_UNIX) || defined(OS_MSWIN)
18947   { "Revcomp16S", RevComp16SBtn } ,
18948 #endif
18949   { "Reverse author names", RevAuthNamesBtn },
18950   { "Rm Consortium", RemovePubConsortiumsBtn },
18951   { "Rm Culture Notes", RemoveUnculturedNotesBtn } ,
18952   { "Rm Text In String", RmTextInsideStringBtn },
18953   { "Rm Text Out String", RmTextOutsideStringBtn },
18954   { "rRNA", ToolBtn6 } ,
18955   { "rRNA->DNA", RibosomalRNAToGenomicDNAToolBtn } ,
18956   { "Save", ToolBtn1 } ,
18957   { "Segregate", CustomSegregate } ,
18958   { "Select Target", WGSBtnChangeTarget } ,
18959   { "Sequester", SequesterBtn } ,
18960   { "Source File", SourceFileBtn } ,
18961   { "Strain to sp.", StrainToSpBtn } ,
18962   { "Strip Suffix", StripAuthorSuffixBtn },
18963   { "StructKeyword", StructuredCommentKeywordsBtn },
18964   { "sub_affil", ToolBtn11 } ,
18965   { "sub_add", ToolBtn12 } ,
18966   { "SUC", ToolBtn10 } ,
18967   { "Table Reader", NewLoadFeatureQualifierTableToolBtn } ,
18968   { "Table Reader Clip", NewLoadFeatureQualifierTableClipToolBtn },
18969   { "Toolbar", ToolbarBtn },
18970   { "Tax_Fix/Clean_Up", ToolBtn3 } ,
18971   { "Trim Ns", TrimNsFromNucsToolBtn } ,
18972   { "Uncul TaxTool", TaxFixToolBtn } ,
18973   { "Update Single Seq Clip", UpdateSingleSeqClipBtn },
18974   { "Update Mult Seqs Clip", UpdateMultSeqsClipBtn } ,
18975   { "Validate", ToolBtn14 } ,
18976   { "View Sorted Pro", ViewSortedProBtn } ,
18977   { "WrongQuals to Note", CustomMoveWrongQuals },
18978   { NULL, NULL} };
18979 
ListCustomToolbarFunctions(IteM i)18980 static void ListCustomToolbarFunctions (IteM i)
18981 {
18982   FILE *fp;
18983   Char path [PATH_MAX];
18984   Int4 j;
18985 
18986   TmpNam (path);
18987   fp = FileOpen (path, "w");
18988   if (fp != NULL) {
18989     for (j = 0; CustomButtons[j].name != NULL; j++) {
18990       fprintf (fp, "%s\n", CustomButtons[j].name);
18991     }
18992     FileClose (fp);
18993     LaunchGeneralTextViewer (path, "Available Custom Toolbar Buttons");
18994     FileRemove (path);
18995   }
18996 
18997 }
18998 
18999 
19000 typedef struct custommacrobtn {
19001   ButtoN btn;
19002   CharPtr macro_path;
19003 } CustomMacroBtnData, PNTR CustomMacroBtnPtr;
19004 
CustomMacroBtnFree(CustomMacroBtnPtr b)19005 static CustomMacroBtnPtr CustomMacroBtnFree (CustomMacroBtnPtr b)
19006 {
19007   if (b != NULL) {
19008     b->macro_path = MemFree (b->macro_path);
19009     b = MemFree (b);
19010   }
19011   return b;
19012 }
19013 
19014 
CustomMacroBtnNew(ButtoN b,CharPtr path)19015 static CustomMacroBtnPtr CustomMacroBtnNew (ButtoN b, CharPtr path)
19016 {
19017   CustomMacroBtnPtr cb;
19018 
19019   cb = (CustomMacroBtnPtr) MemNew (sizeof (CustomMacroBtnData));
19020   cb->btn = b;
19021   cb->macro_path = StringSave (path);
19022   return cb;
19023 }
19024 
19025 
19026 typedef struct customtoolbar {
19027   DIALOG_MESSAGE_BLOCK
19028 
19029   DialoG tbs;
19030   GrouP PNTR pages;
19031 
19032   BaseFormPtr bfp;
19033   CharPtr PNTR tab_names;
19034   CustomMacroBtnPtr PNTR macro_btn_list;
19035   Int4 num_macro_btns;
19036 } CustomToolBarData, PNTR CustomToolBarPtr;
19037 
CleanupCustomToolBar(GraphiC g,VoidPtr data)19038 static void CleanupCustomToolBar (GraphiC g, VoidPtr data)
19039 
19040 {
19041   CustomToolBarPtr dlg;
19042   Int4 i;
19043 
19044   dlg = (CustomToolBarPtr) data;
19045   if (dlg != NULL) {
19046     for (i = 0; dlg->tab_names[i] != NULL; i++) {
19047       dlg->tab_names[i] = MemFree (dlg->tab_names[i]);
19048     }
19049     dlg->tab_names = MemFree (dlg->tab_names);
19050     if (dlg->num_macro_btns > 0) {
19051       for (i = 0; i < dlg->num_macro_btns; i++) {
19052         dlg->macro_btn_list[i] = CustomMacroBtnFree(dlg->macro_btn_list[i]);
19053       }
19054       dlg->macro_btn_list = MemFree (dlg->macro_btn_list);
19055       dlg->num_macro_btns = 0;
19056     }
19057   }
19058   MemFree (data);
19059 }
19060 
RunCustomMacroScript(BaseFormPtr bfp,CharPtr path)19061 static void RunCustomMacroScript (BaseFormPtr bfp, CharPtr path)
19062 {
19063   AsnIoPtr     aip;
19064   ValNodePtr   action_list;
19065   ValNodePtr   sep_list;
19066   ValNodePtr   vnp;
19067   SeqEntryPtr  sep;
19068   Uint2        entityID;
19069   LogInfoPtr   lip;
19070 
19071   if (bfp == NULL) return;
19072 
19073 
19074   aip = AsnIoOpen (path, "r");
19075   if (aip == NULL) {
19076     Message (MSG_ERROR, "Unable to open %s", path);
19077     return;
19078   }
19079 
19080   action_list = MacroActionListAsnRead (aip, NULL);
19081   AsnIoClose (aip);
19082 
19083   if (action_list == NULL) {
19084     Message (MSG_ERROR, "Unable to read action list from %s.", path);
19085     return;
19086   }
19087 
19088   sep_list = GetViewedSeqEntryList ();
19089   if (sep_list == NULL) {
19090     Message (MSG_ERROR, "No records open!");
19091   } else if (sep_list->next != NULL
19092     && ANS_CANCEL == Message (MSG_OKC, "You have more than one record open - run macro for all open records?")) {
19093     /* do nothing */
19094   } else {
19095     WatchCursor();
19096     Update();
19097     lip = OpenLog (path);
19098     for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
19099       sep = vnp->data.ptrvalue;
19100       entityID = ObjMgrGetEntityIDForChoice(sep);
19101       lip->data_in_log |= ApplyMacroToSeqEntryEx (sep, action_list, lip->fp, Sequin_GlobalAlign2Seq);
19102       ObjMgrSetDirtyFlag (entityID, TRUE);
19103       ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
19104     }
19105     CloseLog(lip);
19106     lip = FreeLog(lip);
19107     sep_list = ValNodeFree (sep_list);
19108     ArrowCursor ();
19109     Update ();
19110   }
19111   action_list = MacroActionListFree (action_list);
19112 }
19113 
CustomMacroBtnFunc(ButtoN b)19114 static void CustomMacroBtnFunc (ButtoN b)
19115 {
19116   CustomToolBarPtr dlg;
19117   Int4 i;
19118 
19119   dlg = (CustomToolBarPtr) GetObjectExtra (b);
19120   if (dlg == NULL) {
19121     return;
19122   }
19123   for (i = 0; i < dlg->num_macro_btns; i++) {
19124     if (dlg->macro_btn_list[i]->btn == b) {
19125       RunCustomMacroScript(dlg->bfp, dlg->macro_btn_list[i]->macro_path);
19126       break;
19127     }
19128   }
19129 }
19130 
19131 
ChangeCustomToolbarPage(VoidPtr data,Int2 newval,Int2 oldval)19132 static void ChangeCustomToolbarPage (VoidPtr data, Int2 newval, Int2 oldval)
19133 
19134 {
19135   CustomToolBarPtr dlg;
19136 
19137   dlg = (CustomToolBarPtr) data;
19138   if (dlg != NULL) {
19139     SafeHide (dlg->pages [oldval]);
19140     Update ();
19141     SafeShow (dlg->pages [newval]);
19142     Update ();
19143   }
19144 }
19145 
MakeCustomToolBarData(GrouP h,Pointer data)19146 extern void MakeCustomToolBarData (GrouP h, Pointer data)
19147 
19148 {
19149   BaseFormPtr  bfp;
19150   GrouP        g, g2;
19151   CharPtr      ini_name;
19152   Char         str[PATH_MAX];
19153   Char         buf[32];
19154   Int4         num_tabs, i, num_buttons, num_cols, j, k;
19155   CustomToolBarPtr dlg;
19156   ValNodePtr   macro_list = NULL, vnp;
19157   CharPtr      btn_name, cp;
19158   ButtoN       b;
19159 
19160   bfp = (BaseFormPtr) GetObjectExtra (h);
19161   if (bfp == NULL) return;
19162 
19163   ini_name = (CharPtr) data;
19164   if (ini_name == NULL) {
19165     return;
19166   }
19167   if (!GetAppParam (ini_name, "MAIN", "NUM_TABS", NULL, str, sizeof (str))) {
19168     return;
19169   }
19170   num_tabs = atoi (str);
19171 
19172   g = HiddenGroup (h, -1, 0, NULL);
19173 
19174   dlg = (CustomToolBarPtr) MemNew (sizeof (CustomToolBarData));
19175   SetObjectExtra (g, dlg, CleanupCustomToolBar);
19176 
19177   dlg->bfp = bfp;
19178 
19179   dlg->tab_names = (CharPtr PNTR) MemNew (sizeof (CharPtr) * (num_tabs + 1));
19180   for (i = 0; i < num_tabs; i++) {
19181     sprintf (buf, "GROUP%d", i + 1);
19182     if (GetAppParam (ini_name, "MAIN", buf, NULL, str, sizeof (str))) {
19183       dlg->tab_names[i] = StringSave (str);
19184     } else {
19185       dlg->tab_names[i] = StringSave (buf);
19186     }
19187   }
19188   dlg->tab_names[i] = NULL;
19189 
19190   dlg->tbs = CreateFolderTabs (g, dlg->tab_names, 0, 0, 0,
19191                               SYSTEM_FOLDER_TAB,
19192                               ChangeCustomToolbarPage, (Pointer) dlg);
19193 
19194   dlg->pages = (GrouP PNTR) MemNew (sizeof (GrouP) * num_tabs);
19195   g2 = HiddenGroup (g, 0, 0, NULL);
19196   for (i = 0; i < num_tabs; i++) {
19197     num_cols = 1;
19198     if (GetAppParam (ini_name, dlg->tab_names[i], "NUM_COLS", NULL, str, sizeof (str))) {
19199       num_cols = atoi (str);
19200       if (num_cols < 1) {
19201         num_cols = 1;
19202       }
19203     }
19204 
19205     dlg->pages[i] = HiddenGroup (g2, num_cols, 0, NULL);
19206     SetGroupSpacing (g2, 2, 2);
19207     if (GetAppParam (ini_name, dlg->tab_names[i], "NUM_BUTTONS", NULL, str, sizeof (str))) {
19208       num_buttons = atoi (str);
19209       for (j = 0; j < num_buttons; j++) {
19210         sprintf (buf, "BUTTON%d", j + 1);
19211         if (GetAppParam (ini_name, dlg->tab_names[i], buf, NULL, str, sizeof (str))) {
19212           /* note = later, look up function in list */
19213           for (k = 0; CustomButtons[k].name != NULL && StringICmp (CustomButtons[k].name, str) != 0; k++);
19214           if (CustomButtons[k].name != NULL) {
19215             SqnPushButton (dlg->pages[i], CustomButtons[k].name, CustomButtons[k].proc, bfp);
19216           } else if (StringICmp (str, "Separator") == 0) {
19217             NormalGroup (dlg->pages[i], 0, 0, "", programFont, NULL);
19218           } else {
19219             /* it's a macro */
19220             cp = StringRChr (str, '\\');
19221             if (cp == NULL) {
19222               btn_name = StringSave (str);
19223             } else {
19224               btn_name = StringSave (cp + 1);
19225             }
19226             b = SqnPushButton (dlg->pages[i], btn_name, CustomMacroBtnFunc, (BaseFormPtr) dlg);
19227             ValNodeAddPointer (&macro_list, 0, CustomMacroBtnNew(b, str));
19228             btn_name = MemFree (btn_name);
19229           }
19230         }
19231       }
19232     }
19233     Hide (dlg->pages[i]);
19234   }
19235 
19236   dlg->num_macro_btns = ValNodeLen (macro_list);
19237   dlg->macro_btn_list = (CustomMacroBtnPtr PNTR) MemNew (sizeof (CustomMacroBtnPtr) * dlg->num_macro_btns);
19238   for (k = 0, vnp = macro_list; k < dlg->num_macro_btns && vnp != NULL; k++, vnp = vnp->next) {
19239     dlg->macro_btn_list[k] = vnp->data.ptrvalue;
19240     vnp->data.ptrvalue = NULL;
19241   }
19242   macro_list = ValNodeFree (macro_list);
19243 
19244   SetValue (dlg->tbs, 0);
19245   Show (dlg->pages[0]);
19246 
19247 }
19248 
19249 
19250 static const CharPtr customtoolbarini = "customtoolbar1";
19251 
19252 
19253 
MakeCustomToolbar(IteM i)19254 static void MakeCustomToolbar (IteM i)
19255 
19256 {
19257   BaseFormPtr  bfp;
19258   ForM         f;
19259 
19260 #ifdef WIN_MAC
19261   bfp = currentFormDataPtr;
19262 #else
19263   bfp = GetObjectExtra (i);
19264 #endif
19265   if (bfp == NULL) return;
19266   f = ReplaceToolFormWithDataForBioseqView (bfp, MakeCustomToolBarData, customtoolbarini);
19267   Show (f);
19268   Select (f);
19269 }
19270 
19271 
BioseqViewFormCustomToolBar(GrouP h)19272 extern void BioseqViewFormCustomToolBar (GrouP h)
19273 
19274 {
19275   MakeCustomToolBarData (h, customtoolbarini);
19276 }
19277 
19278 
DoNCCleanup(IteM i)19279 static void DoNCCleanup (IteM i)
19280 
19281 {
19282   BaseFormPtr  bfp;
19283   SeqEntryPtr  sep;
19284 
19285 #ifdef WIN_MAC
19286   bfp = currentFormDataPtr;
19287 #else
19288   bfp = GetObjectExtra (i);
19289 #endif
19290   if (bfp == NULL) return;
19291 
19292   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
19293   if (sep == NULL) return;
19294 
19295   NC_Cleanup (bfp->input_entityID, NULL);
19296 
19297   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
19298   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
19299   Update ();
19300 }
19301 
DoSSECleanup(IteM i)19302 static void DoSSECleanup (IteM i)
19303 
19304 {
19305   BaseFormPtr  bfp;
19306   SeqEntryPtr  sep;
19307 
19308 #ifdef WIN_MAC
19309   bfp = currentFormDataPtr;
19310 #else
19311   bfp = GetObjectExtra (i);
19312 #endif
19313   if (bfp == NULL) return;
19314 
19315   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
19316   if (sep == NULL) return;
19317 
19318   SeriousSeqEntryCleanup (sep, NULL, NULL);
19319 
19320   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
19321   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
19322   Update ();
19323 }
19324 
MarkProtTitlesProc(BioseqPtr bsp,Pointer userdata)19325 static void MarkProtTitlesProc (BioseqPtr bsp, Pointer userdata)
19326 
19327 {
19328   ObjValNodePtr  ovp;
19329   SeqDescrPtr    sdp;
19330 
19331   if (bsp == NULL) return;
19332   if (! ISA_aa (bsp->mol)) return;
19333 
19334   for (sdp = bsp->descr; sdp != NULL; sdp = sdp->next) {
19335     if (sdp->choice == Seq_descr_title) {
19336       if (sdp->extended != 0) {
19337         ovp = (ObjValNodePtr) sdp;
19338         ovp->idx.deleteme = TRUE;
19339       }
19340     }
19341   }
19342 }
19343 
DoRemoveAllProtTitles(IteM i)19344 static void DoRemoveAllProtTitles (IteM i)
19345 
19346 {
19347   BaseFormPtr  bfp;
19348   SeqEntryPtr  sep;
19349 
19350 #ifdef WIN_MAC
19351   bfp = currentFormDataPtr;
19352 #else
19353   bfp = GetObjectExtra (i);
19354 #endif
19355   if (bfp == NULL) return;
19356 
19357   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
19358   if (sep == NULL) return;
19359 
19360   VisitBioseqsInSep (sep, NULL, MarkProtTitlesProc);
19361   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
19362 
19363   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
19364   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
19365   Update ();
19366 }
19367 
MarkNucTitlesProc(BioseqPtr bsp,Pointer userdata)19368 static void MarkNucTitlesProc (BioseqPtr bsp, Pointer userdata)
19369 
19370 {
19371   ObjValNodePtr  ovp;
19372   SeqDescrPtr    sdp;
19373 
19374   if (bsp == NULL) return;
19375   if (! ISA_na (bsp->mol)) return;
19376 
19377   for (sdp = bsp->descr; sdp != NULL; sdp = sdp->next) {
19378     if (sdp->choice == Seq_descr_title) {
19379       if (sdp->extended != 0) {
19380         ovp = (ObjValNodePtr) sdp;
19381         ovp->idx.deleteme = TRUE;
19382       }
19383     }
19384   }
19385 }
19386 
DoRemoveAllNucTitles(IteM i)19387 static void DoRemoveAllNucTitles (IteM i)
19388 
19389 {
19390   BaseFormPtr  bfp;
19391   SeqEntryPtr  sep;
19392 
19393 #ifdef WIN_MAC
19394   bfp = currentFormDataPtr;
19395 #else
19396   bfp = GetObjectExtra (i);
19397 #endif
19398   if (bfp == NULL) return;
19399 
19400   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
19401   if (sep == NULL) return;
19402 
19403   VisitBioseqsInSep (sep, NULL, MarkNucTitlesProc);
19404   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
19405 
19406   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
19407   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
19408   Update ();
19409 }
19410 
MarkMrnaTitlesProc(BioseqPtr bsp,Pointer userdata)19411 static void MarkMrnaTitlesProc (BioseqPtr bsp, Pointer userdata)
19412 
19413 {
19414   SeqMgrDescContext  dcontext;
19415   MolInfoPtr         mip;
19416   ObjValNodePtr      ovp;
19417   SeqDescrPtr        sdp;
19418 
19419   if (bsp == NULL) return;
19420   if (! ISA_na (bsp->mol)) return;
19421 
19422   sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_molinfo, &dcontext);
19423   if (sdp == NULL || sdp->choice != Seq_descr_molinfo) return;
19424   mip = (MolInfoPtr) sdp->data.ptrvalue;
19425   if (mip == NULL) return;
19426   if (mip->biomol != MOLECULE_TYPE_MRNA) return;
19427 
19428   for (sdp = bsp->descr; sdp != NULL; sdp = sdp->next) {
19429     if (sdp->choice == Seq_descr_title) {
19430       if (sdp->extended != 0) {
19431         ovp = (ObjValNodePtr) sdp;
19432         ovp->idx.deleteme = TRUE;
19433       }
19434     }
19435   }
19436 }
19437 
DoRemoveMrnaTitles(IteM i)19438 static void DoRemoveMrnaTitles (IteM i)
19439 
19440 {
19441   BaseFormPtr  bfp;
19442   SeqEntryPtr  sep;
19443 
19444 #ifdef WIN_MAC
19445   bfp = currentFormDataPtr;
19446 #else
19447   bfp = GetObjectExtra (i);
19448 #endif
19449   if (bfp == NULL) return;
19450 
19451   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
19452   if (sep == NULL) return;
19453 
19454   VisitBioseqsInSep (sep, NULL, MarkMrnaTitlesProc);
19455   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
19456 
19457   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
19458   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
19459   Update ();
19460 }
19461 
MarkNPSTitlesProc(BioseqSetPtr bssp,Pointer userdata)19462 static void MarkNPSTitlesProc (BioseqSetPtr bssp, Pointer userdata)
19463 
19464 {
19465   ObjValNodePtr  ovp;
19466   SeqDescrPtr    sdp;
19467 
19468   if (bssp == NULL) return;
19469   if (bssp->_class != BioseqseqSet_class_nuc_prot) return;
19470 
19471   for (sdp = bssp->descr; sdp != NULL; sdp = sdp->next) {
19472     if (sdp->choice == Seq_descr_title) {
19473       if (sdp->extended != 0) {
19474         ovp = (ObjValNodePtr) sdp;
19475         ovp->idx.deleteme = TRUE;
19476       }
19477     }
19478   }
19479 }
19480 
DoRemoveNPSTitles(IteM i)19481 static void DoRemoveNPSTitles (IteM i)
19482 
19483 {
19484   BaseFormPtr  bfp;
19485   SeqEntryPtr  sep;
19486 
19487 #ifdef WIN_MAC
19488   bfp = currentFormDataPtr;
19489 #else
19490   bfp = GetObjectExtra (i);
19491 #endif
19492   if (bfp == NULL) return;
19493 
19494   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
19495   if (sep == NULL) return;
19496 
19497   VisitSetsInSep (sep, NULL, MarkNPSTitlesProc);
19498   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
19499 
19500   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
19501   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
19502   Update ();
19503 }
19504 
DoPTCleanup(IteM i)19505 static void DoPTCleanup (IteM i)
19506 
19507 {
19508   BaseFormPtr  bfp;
19509   SeqEntryPtr  sep;
19510 
19511 #ifdef WIN_MAC
19512   bfp = currentFormDataPtr;
19513 #else
19514   bfp = GetObjectExtra (i);
19515 #endif
19516   if (bfp == NULL) return;
19517 
19518   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
19519   if (sep == NULL) return;
19520 
19521   InstantiateProteinTitles (bfp->input_entityID, NULL);
19522 
19523   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
19524   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
19525   Update ();
19526 }
19527 
TakeProteinsFromGPS(BioseqPtr bsp,Pointer userdata)19528 static void TakeProteinsFromGPS (BioseqPtr bsp, Pointer userdata)
19529 
19530 {
19531   SeqEntryPtr PNTR  lastp;
19532   SeqEntryPtr       sep;
19533 
19534   if (bsp == NULL || (! ISA_aa (bsp->mol))) return;
19535   lastp = (SeqEntryPtr PNTR) userdata;
19536   if (lastp == NULL) return;
19537 
19538   /* unlink from existing chain */
19539 
19540   sep = bsp->seqentry;
19541   if (sep != NULL) {
19542     sep->data.ptrvalue = NULL;
19543   }
19544 
19545   /* link after genomic sequence */
19546 
19547   sep = ValNodeAddPointer (lastp, 1, (Pointer) bsp);
19548   *lastp = sep;
19549 }
19550 
StripMrnaProducts(SeqFeatPtr sfp,Pointer userdata)19551 static void StripMrnaProducts (SeqFeatPtr sfp, Pointer userdata)
19552 
19553 {
19554   if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA) return;
19555   if (sfp->product == NULL) return;
19556 
19557   sfp->product = SeqLocFree (sfp->product);
19558 }
19559 
GPStoNPS(IteM i)19560 static void GPStoNPS (IteM i)
19561 
19562 {
19563   BaseFormPtr   bfp;
19564   BioseqSetPtr  bssp;
19565   BioseqSet     dum;
19566   SeqEntryPtr   last, sep, top;
19567   Uint2         parenttype;
19568   Pointer       parentptr;
19569 
19570 #ifdef WIN_MAC
19571   bfp = currentFormDataPtr;
19572 #else
19573   bfp = GetObjectExtra (i);
19574 #endif
19575   if (bfp == NULL) return;
19576 
19577   top = GetTopSeqEntryForEntityID (bfp->input_entityID);
19578   if (top == NULL || top->choice != 2) return;
19579   bssp = (BioseqSetPtr) top->data.ptrvalue;
19580   if (bssp != NULL && bssp->_class == BioseqseqSet_class_genbank) {
19581     sep = bssp->seq_set;
19582     if (sep != NULL && IS_Bioseq_set (sep)) {
19583       bssp = (BioseqSetPtr) sep->data.ptrvalue;
19584     }
19585   }
19586   if (bssp == NULL || bssp->_class != BioseqseqSet_class_gen_prod_set) return;
19587 
19588   GetSeqEntryParent (top, &parentptr, &parenttype);
19589 
19590   sep = bssp->seq_set;
19591   if (sep == NULL || sep->choice != 1) return;
19592 
19593   /* unlink nuc-prot sets, etc., from genomic Bioseq */
19594 
19595   MemSet ((Pointer) &dum, 0, sizeof (BioseqSet));
19596   dum._class = 1;
19597   dum.seq_set = sep->next;
19598   sep->next = NULL;
19599 
19600   last = sep;
19601   VisitBioseqsInSet (&dum, (Pointer) &last, TakeProteinsFromGPS);
19602 
19603   /* leave dum.seq_set dangling for now */
19604 
19605   bssp->_class = BioseqseqSet_class_nuc_prot;
19606 
19607   SeqMgrLinkSeqEntry (top, parenttype, parentptr);
19608 
19609   SeqMgrClearFeatureIndexes (bssp->idx.entityID, NULL);
19610 
19611   VisitFeaturesInSet (bssp, NULL, StripMrnaProducts);
19612 
19613   move_cds (top);
19614 
19615   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
19616   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
19617   Update ();
19618 }
19619 
19620 typedef struct marksegfeatsdata {
19621   SeqLocPtr seg_loc;
19622   CdsDelStructPtr   cdsDelInfoPtr;
19623 } MarkSegFeatData, PNTR MarkSegFeatPtr;
19624 
MarkSegmentFeatures(SeqFeatPtr sfp,SeqMgrFeatContextPtr scontext)19625 static Boolean LIBCALLBACK MarkSegmentFeatures (SeqFeatPtr sfp,
19626 					       SeqMgrFeatContextPtr scontext)
19627 {
19628   MarkSegFeatPtr msfp;
19629 
19630   if (sfp == NULL || sfp->idx.subtype != FEATDEF_CDS) return TRUE;
19631   msfp = scontext->userdata;
19632   if (msfp == NULL || msfp->seg_loc == NULL
19633     || msfp->cdsDelInfoPtr == NULL
19634     || sfp->location == NULL)
19635   {
19636     return TRUE;
19637   }
19638   if (SeqLocAinB (sfp->location, msfp->seg_loc) >=0)
19639   {
19640     sfp->idx.deleteme = TRUE;
19641     msfp->cdsDelInfoPtr->dirtyFlag = TRUE;
19642   }
19643   return TRUE;
19644 }
19645 
19646 /*=====================================================================*/
19647 /*                                                                     */
19648 /* RemoveCDS_Callback () - Called for each segment explored in         */
19649 /*                         RemoveNthCDSfromSegSets_Callback(), this    */
19650 /*                         removes the first CDS of a segment.         */
19651 /*                                                                     */
19652 /*=====================================================================*/
19653 
RemoveCDS_Callback(SeqLocPtr slp,SeqMgrSegmentContextPtr scontext)19654 static Boolean LIBCALLBACK RemoveCDS_Callback (SeqLocPtr slp,
19655 					       SeqMgrSegmentContextPtr scontext)
19656 {
19657   BioseqPtr         bsp;
19658   MarkSegFeatData   msf;
19659 
19660   /* If not the Nth segment, skip */
19661 
19662   msf.cdsDelInfoPtr = (CdsDelStructPtr) scontext->userdata;
19663   if (scontext->index != msf.cdsDelInfoPtr->number)
19664     return TRUE;
19665 
19666   /* Else, delete its CDS */
19667 
19668   else {
19669 
19670     /* Mark the coding regions for this segment */
19671     bsp = BioseqFindFromSeqLoc (slp);
19672     msf.seg_loc = slp;
19673     SeqMgrExploreFeatures (bsp, (Pointer) &msf, MarkSegmentFeatures, NULL, NULL, NULL);
19674 
19675     /* We only want to remove a CDS from the Nth   */
19676     /* segment so stop the exploring at this point */
19677 
19678     return FALSE;
19679   }
19680 }
19681 
19682 /*=====================================================================*/
19683 /*                                                                     */
19684 /* RemoveNthCDS() - Remove the CDS from the first segment of a given   */
19685 /*                  segmented sequence.                                */
19686 /*                                                                     */
19687 /*=====================================================================*/
19688 
RemoveNthCDS(SeqEntryPtr sep,CdsDelStructPtr cdsDelInfoPtr)19689 static void RemoveNthCDS (SeqEntryPtr      sep,
19690 			  CdsDelStructPtr  cdsDelInfoPtr)
19691 {
19692   BioseqPtr     bsp;
19693   BioseqSetPtr  bssp;
19694   Int4          segCount;
19695 
19696   /* If the SeqEntry is a Bioseq, then remove */
19697   /* the Nth CDS from each segment.           */
19698 
19699   if (IS_Bioseq(sep))
19700     {
19701       bsp = (BioseqPtr) sep->data.ptrvalue;
19702       if (bsp->repr == Seq_repr_seg)
19703 	segCount = SeqMgrExploreSegments (bsp, cdsDelInfoPtr,
19704 					  RemoveCDS_Callback);
19705     }
19706 
19707   /* If we have a Bioseq set, then recursively call */
19708   /* this function for each member of the set.      */
19709 
19710   else
19711     {
19712       bssp = (BioseqSetPtr) sep->data.ptrvalue;
19713       for (sep = bssp->seq_set; sep != NULL; sep = sep->next)
19714     	RemoveNthCDS (sep, cdsDelInfoPtr);
19715     }
19716 
19717 }
19718 
19719 /*=====================================================================*/
19720 /*                                                                     */
19721 /* RemoveNthCDS_AcceptCallback () --                                   */
19722 /*                                                                     */
19723 /*=====================================================================*/
19724 
RemoveNthCDS_AcceptCallback(ButtoN b)19725 static void RemoveNthCDS_AcceptCallback (ButtoN b)
19726 {
19727   CdsDelFormPtr cdfp;
19728   SeqEntryPtr   sep;
19729   Uint2         entityID;
19730   CdsDelStruct  cdsDelInfo;
19731 
19732   /* Make sure that conditions are right */
19733 
19734   cdfp = GetObjectExtra (b);
19735   if (NULL == cdfp) {
19736     Remove (ParentWindow (b));
19737     Update ();
19738     return;
19739   }
19740 
19741   if (cdfp->number == 0) {
19742     Remove (ParentWindow (b));
19743     MemFree (cdfp);
19744     Update ();
19745     return;
19746   }
19747 
19748   /* Get the top level SeqEntry */
19749 
19750   sep = GetTopSeqEntryForEntityID (cdfp->input_entityID);
19751   if (sep == NULL) {
19752     Remove (ParentWindow (b));
19753     MemFree (cdfp);
19754     Update ();
19755     return;
19756   }
19757 
19758   /* Remove CDS from segments */
19759 
19760   WatchCursor ();
19761   Update ();
19762 
19763   cdsDelInfo.dirtyFlag = FALSE;
19764   cdsDelInfo.number    = cdfp->number;
19765 
19766   RemoveNthCDS (sep, &cdsDelInfo);
19767 
19768   /* If any CDS were marked for deletion */
19769   /* then delete them and update.        */
19770 
19771   if (TRUE == cdsDelInfo.dirtyFlag)
19772     {
19773       entityID = ObjMgrGetEntityIDForChoice (sep);
19774       DeleteMarkedObjects (entityID, 0, NULL);
19775       Update ();
19776       ObjMgrSetDirtyFlag (entityID, TRUE);
19777       ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
19778     }
19779 
19780   /* Update the display */
19781 
19782   Remove (ParentWindow (b));
19783   MemFree (cdfp);
19784   ArrowCursor ();
19785   Update ();
19786 }
19787 
19788 /*=====================================================================*/
19789 /*                                                                     */
19790 /* GetN_Callback () --                                                 */
19791 /*                                                                     */
19792 /*=====================================================================*/
19793 
GetN_Callback(TexT nText)19794 static void GetN_Callback (TexT nText)
19795 
19796 {
19797   CdsDelFormPtr cdfp;
19798   CharPtr       nStr;
19799 
19800   cdfp = (CdsDelFormPtr) GetObjectExtra (nText);
19801   if (cdfp == NULL)
19802     return;
19803 
19804   nStr = SaveStringFromText (nText);
19805   cdfp->number = atoi (nStr);
19806 
19807 }
19808 
19809 /*=====================================================================*/
19810 /*                                                                     */
19811 /* CreateGetNWindow () --                                              */
19812 /*                                                                     */
19813 /*=====================================================================*/
19814 
CreateGetNWindow(CdsDelFormPtr cdfp)19815 static ForM CreateGetNWindow (CdsDelFormPtr cdfp)
19816 {
19817   /*
19818   FindFormPtr        ffp;
19819   GrouP              q = NULL;
19820   */
19821 
19822   ButtoN             b;
19823   GrouP              c;
19824   GrouP              g;
19825   GrouP              j;
19826   StdEditorProcsPtr  sepp;
19827   WindoW             w;
19828   TexT               nthText;
19829 
19830   w = ModalWindow (-50, -30, -10, -10, StdCloseWindowProc);
19831   cdfp->form = (ForM) w;
19832 
19833 #ifndef WIN_MAC
19834   CreateStdEditorFormMenus (w);
19835 #endif
19836 
19837   sepp = (StdEditorProcsPtr) GetAppProperty ("StdEditorForm");
19838   if (sepp != NULL) {
19839     SetActivate (w, sepp->activateForm);
19840   }
19841 
19842   j = HiddenGroup (w, -1, 0, NULL);
19843   SetGroupSpacing (j, 10, 10);
19844 
19845   g = HiddenGroup (j, 2, 0, NULL);
19846   StaticPrompt (g, "CDS to Delete", 0, dialogTextHeight, programFont, 'l');
19847   nthText = DialogText (g, "", 6, (TxtActnProc) GetN_Callback);
19848   SetObjectExtra (nthText, cdfp, NULL);
19849 
19850   c = HiddenGroup (w, 4, 0, NULL);
19851   SetGroupSpacing (c, 10, 2);
19852   b = DefaultButton (c, "Accept", RemoveNthCDS_AcceptCallback);
19853   SetObjectExtra (b, cdfp, NULL);
19854   PushButton (c, "Cancel", StdCancelButtonProc);
19855   AlignObjects (ALIGN_CENTER, (HANDLE) j, (HANDLE) c, NULL);
19856 
19857   RealizeWindow (w);
19858 
19859   return (ForM) w;
19860 }
19861 
19862 /*=====================================================================*/
19863 /*                                                                     */
19864 /* RemoveNthCDSFromSegSets_Callback() - Remove the CDS from the first  */
19865 /*                                      segment of all Bioseqs.        */
19866 /*                                                                     */
19867 /*=====================================================================*/
19868 
RemoveNthCDSFromSegSets_Callback(IteM i)19869 static void RemoveNthCDSFromSegSets_Callback (IteM i)
19870 {
19871   ForM          w;
19872   CdsDelFormPtr cdfp;
19873   BaseFormPtr   bfp;
19874 
19875 #ifdef WIN_MAC
19876   bfp = currentFormDataPtr;
19877 #else
19878   bfp = GetObjectExtra (i);
19879 #endif
19880   if (bfp == NULL)
19881     return;
19882 
19883   cdfp = (CdsDelFormPtr) MemNew (sizeof (CdsDelForm));
19884 
19885   /* Find out which segments to delete the CDS from */
19886 
19887   cdfp->input_entityID = bfp->input_entityID;
19888   w = CreateGetNWindow (cdfp);
19889   Show (w);
19890   Select (w);
19891 }
19892 
19893 /*---------------------------------------------------------------------*/
19894 /*                                                                     */
19895 /* RemoveSeqIdName_FeatureCallback () --                               */
19896 /*                                                                     */
19897 /*---------------------------------------------------------------------*/
19898 
RemoveSeqIdName_FeatureCallback(SeqFeatPtr sfp,SeqMgrFeatContextPtr fcontext)19899 static Boolean LIBCALLBACK RemoveSeqIdName_FeatureCallback
19900                                (SeqFeatPtr sfp,
19901 				SeqMgrFeatContextPtr fcontext)
19902 {
19903   SeqIdPtr     sip;
19904   TextSeqIdPtr tsip;
19905 
19906   /* If we don't have a product then */
19907   /* go on to the next seq feat.     */
19908 
19909   if (sfp->product == NULL)
19910     return TRUE;
19911 
19912   /* Otherwise check the id name field */
19913 
19914   sip = SeqLocId (sfp->product);
19915   if (sip != NULL) {
19916       switch (sip->choice) {
19917         case SEQID_LOCAL :
19918 	  break;
19919         case SEQID_GENBANK :
19920         case SEQID_EMBL :
19921         case SEQID_DDBJ :
19922         case SEQID_OTHER :
19923         case SEQID_TPG :
19924         case SEQID_TPE :
19925         case SEQID_TPD :
19926           tsip = (TextSeqIdPtr) sip->data.ptrvalue;
19927           if ((tsip != NULL) &&
19928 	      (tsip->accession == NULL) &&
19929 	      (! StringHasNoText (tsip->name)) &&
19930 	      (IsNuclAcc (tsip->name)))
19931 	    tsip->name[0] = '\0';
19932           break;
19933         default :
19934           break;
19935       }
19936     }
19937 
19938   /* Return TRUE to continue on to the next feature */
19939 
19940   return TRUE;
19941 }
19942 
19943 /*---------------------------------------------------------------------*/
19944 /*                                                                     */
19945 /* RemoveSeqIdName_BioseqCallback () --                                */
19946 /*                                                                     */
19947 /*---------------------------------------------------------------------*/
19948 
RemoveSeqIdName_BioseqCallback(BioseqPtr bsp,SeqMgrBioseqContextPtr bcontext)19949 static Boolean LIBCALLBACK RemoveSeqIdName_BioseqCallback (BioseqPtr bsp,
19950 					 SeqMgrBioseqContextPtr bcontext)
19951 {
19952   TextSeqIdPtr tsip;
19953 
19954   /* If it is a protein Bioseq then */
19955   /* check the ID name field.       */
19956 
19957   if (ISA_aa (bsp->mol))
19958     {
19959       if (bsp->id != NULL) {
19960 	switch (bsp->id->choice)
19961 	  {
19962           case SEQID_GENBANK :
19963           case SEQID_EMBL :
19964           case SEQID_DDBJ :
19965           case SEQID_OTHER :
19966           case SEQID_TPG :
19967 	  case SEQID_TPE :
19968 	  case SEQID_TPD :
19969 	    tsip = (TextSeqIdPtr) bsp->id->data.ptrvalue;
19970 	    if ((tsip != NULL) &&
19971 		(tsip->accession == NULL) &&
19972 		(! StringHasNoText (tsip->name)) &&
19973 		(IsNuclAcc (tsip->name)))
19974 	      {
19975 		tsip->name[0] = '\0';
19976 	      }
19977 	    break;
19978 	  default :
19979 	    break;
19980 	  }
19981       }
19982     }
19983 
19984   /* Else for nucl bioseqs check the name */
19985   /* field of the protein sfps.           */
19986 
19987   else
19988     SeqMgrExploreFeatures (bsp, NULL, RemoveSeqIdName_FeatureCallback,
19989 			   NULL, NULL, NULL);
19990 
19991   /* Return TRUE to continue on to the next Bioseq */
19992 
19993   return TRUE;
19994 }
19995 
19996 /*=====================================================================*/
19997 /*                                                                     */
19998 /* RemoveSeqIdName_Callback() - Remove the contents of the seq-id name */
19999 /*                              field in the cases where there is no   */
20000 /*                              corresponding GI number.               */
20001 /*                                                                     */
20002 /*=====================================================================*/
20003 
RemoveSeqIdName_Callback(IteM i)20004 static void RemoveSeqIdName_Callback (IteM i)
20005 {
20006   BaseFormPtr   bfp;
20007   SeqEntryPtr   sep;
20008 
20009 #ifdef WIN_MAC
20010   bfp = currentFormDataPtr;
20011 #else
20012   bfp = GetObjectExtra (i);
20013 #endif
20014   if (bfp == NULL)
20015     return;
20016 
20017   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
20018   if (sep == NULL)
20019     return;
20020 
20021   SeqMgrExploreBioseqs (bfp->input_entityID, NULL, bfp,
20022 			RemoveSeqIdName_BioseqCallback,
20023 			TRUE, TRUE, TRUE);
20024 
20025   /* Force an update and redraw */
20026 
20027   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
20028   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
20029   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
20030   ArrowCursor ();
20031   Update ();
20032 
20033   /* Return successfully */
20034 
20035   return;
20036 
20037 }
20038 
ReverseNameOrderInAuthor(AuthorPtr pAuthor)20039 static void ReverseNameOrderInAuthor (AuthorPtr pAuthor)
20040 {
20041   NameStdPtr pNameStandard;
20042   NameStdPtr pNewName;
20043   CharPtr	first_name;
20044   CharPtr	middle_initial;
20045   CharPtr	last_name;
20046   CharPtr	suffix;
20047   Char		str[128];
20048   CharPtr	pTmp;
20049 
20050   if (pAuthor == NULL)
20051     return;
20052   else if(pAuthor->name->choice != 2)
20053     return;
20054   pNameStandard = pAuthor->name->data;
20055   if (pNameStandard != NULL)
20056   {
20057     pTmp = NameStdPtrToAuthorSpreadsheetString(pNameStandard);
20058     first_name = ExtractTagListColumn(pTmp, 2);
20059     middle_initial = ExtractTagListColumn(pTmp, 1);
20060     last_name = ExtractTagListColumn(pTmp, 0);
20061     suffix = ExtractTagListColumn(pTmp, 3);
20062     sprintf(str, "%s\t%s\t%s\t%s\n",
20063 	first_name, middle_initial, last_name, suffix);
20064     MemFree(first_name);
20065     MemFree(middle_initial);
20066     MemFree(last_name);
20067     MemFree(suffix);
20068     pNewName = AuthorSpreadsheetStringToNameStdPtr(str);
20069     NameStdFree(pNameStandard);
20070     pAuthor->name->data = pNewName;
20071   }
20072 
20073 }
20074 
ChangeAuthorLastNameToConsortium(AuthorPtr pAuthor,StringConstraintXPtr author_scp)20075 static void ChangeAuthorLastNameToConsortium (AuthorPtr pAuthor, StringConstraintXPtr author_scp)
20076 {
20077   NameStdPtr pNameStandard;
20078   CharPtr    consortium;
20079   Int4       len;
20080 
20081   if (pAuthor == NULL || pAuthor->name == NULL || pAuthor->name->choice == 5)
20082   {
20083   	return;
20084   }
20085   if (pAuthor->name->choice == 2)
20086   {
20087     pNameStandard = pAuthor->name->data;
20088     if (pNameStandard != NULL)
20089     {
20090       len = StringLen (pNameStandard->names[0]);
20091       if (len > 0)
20092       {
20093         if (DoesStringMatchConstraintX (pNameStandard->names[0], author_scp))
20094         {
20095     	    consortium = (CharPtr) MemNew ((len + 1) * sizeof (Char));
20096     	    if (consortium != NULL)
20097   	      {
20098   	        StringCpy (consortium, pNameStandard->names[0]);
20099   	        NameStdFree (pNameStandard);
20100   	        pAuthor->name->choice = 5;
20101   	        pAuthor->name->data = consortium;
20102   	      }
20103   	    }
20104       }
20105     }
20106   }
20107 }
20108 
20109 
20110 typedef struct fixpubdesc
20111 {
20112   Int4                iType;
20113   StringConstraintXPtr author_scp;
20114   ValNodePtr          org_names;
20115 } FixPubdescData, PNTR FixPubdescPtr;
20116 
20117 
FixPubAuthors(AuthListPtr alp,Int4 iType,StringConstraintXPtr author_scp)20118 static void FixPubAuthors(AuthListPtr alp, Int4 iType, StringConstraintXPtr author_scp)
20119 {
20120   ValNodePtr	names;
20121   AuthorPtr	    ap;
20122 
20123   if (alp == NULL) {
20124     return;
20125   }
20126     /* Loop through author list */
20127     for (names = alp->names; names != NULL; names = names->next) {
20128       ap = names->data.ptrvalue;
20129       if(iType & FIX_PUB_AUTHOR_CAPITALIZATION ) {
20130         FixCapitalizationInAuthor (ap);
20131       }
20132       if(iType & FIX_AUTHOR_NAME_ORDER ) {
20133         ReverseNameOrderInAuthor (ap);
20134       }
20135       if (iType & TRUNCATE_AUTHOR_MIDDLE_INITIALS)
20136       {
20137         TruncateAuthorMiddleInitials (ap);
20138       }
20139       if (iType & STRIP_AUTHOR_SUFFIX) {
20140         StripSuffixFromAuthor (ap);
20141       }
20142       if (iType & FIX_PUB_SWAP_NAME_CONSORTIUM)
20143       {
20144       	ChangeAuthorLastNameToConsortium (ap, author_scp);
20145       }
20146     }
20147 
20148     if (alp->affil != NULL) {
20149       if (iType & FIX_PUB_AFFIL_CAPITALIZATION ) {
20150         FixCapsInPubAffil (alp->affil);
20151       } else if (iType & FIX_PUB_AFFIL_COUNTRY_CAPITALIZATION ) {
20152         FixCapitalizationInCountryString (&(alp->affil->country));
20153       }
20154     }
20155 }
20156 
20157 
FixPubdesc(PubdescPtr pdp,Pointer userdata)20158 static void FixPubdesc (PubdescPtr pdp, Pointer userdata)
20159 {
20160   ValNodePtr	  vnp;
20161   AuthListPtr 	alp;
20162   CitArtPtr     cap;
20163   CitBookPtr    cbp;
20164   CitGenPtr     cgp;
20165   CitPatPtr     cpp;
20166   CitSubPtr     csp;
20167   CharPtr PNTR	title;
20168   Int4	        iType;
20169   FixPubdescPtr fpp;
20170 
20171   fpp = (FixPubdescPtr) userdata;
20172   if (fpp == NULL)
20173   {
20174     return;
20175   }
20176 
20177   iType = fpp->iType;
20178 
20179   if (pdp == NULL) return;
20180   /* search for PUB_PMid or PUB_Muid - if found, do not edit this pub */
20181   for (vnp = pdp->pub; vnp != NULL; vnp = vnp->next) {
20182     if (vnp->choice == PUB_PMid || vnp->choice == PUB_Muid) return;
20183   }
20184   for (vnp = pdp->pub; vnp != NULL; vnp = vnp->next) {
20185     if (vnp->choice == PUB_PMid || vnp->choice == PUB_Muid) continue;
20186     if (vnp->data.ptrvalue == NULL) continue;
20187     alp = NULL;
20188     title = NULL;
20189     switch (vnp->choice) {
20190       case PUB_Gen :
20191         cgp = (CitGenPtr) vnp->data.ptrvalue;
20192         if( !(cgp->cit != NULL && StringCmp(cgp->cit, "unpublished") != 0)
20193   	      && !((iType & FIX_SELECTED) || (iType & FIX_ALL)) ) continue;
20194         alp = cgp->authors;
20195         title = &(cgp->title);
20196         break;
20197       case PUB_Sub :
20198         csp = (CitSubPtr) vnp->data.ptrvalue;
20199         alp = csp->authors;
20200         title = NULL;
20201         break;
20202       case PUB_Article :
20203         if ( !((iType & FIX_SELECTED) || (iType & FIX_ALL)) ) continue;
20204         cap = (CitArtPtr) vnp->data.ptrvalue;
20205         alp = cap->authors;
20206         if(cap->title != NULL) {
20207           title = (CharPtr PNTR) &(cap->title->data.ptrvalue);
20208         }
20209         break;
20210       case PUB_Book :
20211       case PUB_Man :
20212         if ( !((iType & FIX_SELECTED) || (iType & FIX_ALL)) ) continue;
20213         cbp = (CitBookPtr) vnp->data.ptrvalue;
20214         alp = cbp->authors;
20215         if(cbp->title != NULL) {
20216           title = (CharPtr PNTR) &(cbp->title->data.ptrvalue);
20217         }
20218         break;
20219       case PUB_Patent :
20220         if ( !((iType & FIX_SELECTED) || (iType & FIX_ALL)) ) continue;
20221         cpp = (CitPatPtr) vnp->data.ptrvalue;
20222         alp = cpp->authors;
20223         title = &(cpp->title);
20224         break;
20225       default :
20226         break;
20227     }
20228 
20229     if(iType & FIX_PUB_TITLE_CAPITALIZATION ) {
20230       FixCapitalizationInTitle (title, TRUE, fpp->org_names);
20231     }
20232 
20233     FixPubAuthors(alp, iType, fpp->author_scp);
20234   }
20235 }
20236 
20237 
GetOrgNamesInRecordCallback(BioSourcePtr biop,Pointer userdata)20238 extern void GetOrgNamesInRecordCallback (BioSourcePtr biop, Pointer userdata)
20239 {
20240   ValNodePtr PNTR org_names;
20241 
20242   if (biop == NULL || biop->org == NULL || StringHasNoText (biop->org->taxname)
20243       || userdata == NULL)
20244   {
20245     return;
20246   }
20247 
20248   org_names = (ValNodePtr PNTR) userdata;
20249 
20250   ValNodeAddPointer (org_names, 0, biop->org->taxname);
20251 }
20252 
20253 
AreAnySelectedPubs(Uint2 entityID,SelStructPtr sel)20254 static Boolean AreAnySelectedPubs (Uint2 entityID, SelStructPtr sel)
20255 {
20256   SeqFeatPtr sfp;
20257   SeqMgrFeatContext fcontext;
20258   SeqDescPtr sdp;
20259   SeqMgrDescContext dcontext;
20260   Boolean rval = FALSE;
20261 
20262   while( sel != NULL && !rval )
20263   {
20264     if(sel->entityID == entityID)
20265     {
20266       if(sel->itemtype == OBJ_SEQFEAT)
20267       {
20268         sfp = SeqMgrGetDesiredFeature (entityID, NULL, sel->itemID, 0, NULL, &fcontext);
20269         if(sfp != NULL && sfp->data.choice == SEQFEAT_PUB)
20270         {
20271           rval = TRUE;
20272         }
20273       }
20274       else if(sel->itemtype == OBJ_SEQDESC)
20275       {
20276         sdp = SeqMgrGetDesiredDescriptor (entityID, NULL, sel->itemID, 0, NULL, &dcontext);
20277         if(sdp != NULL && sdp->choice == Seq_descr_pub)
20278         {
20279           rval = TRUE;
20280         }
20281       }
20282     }
20283     sel = sel->next;
20284   }
20285   return rval;
20286 }
20287 
20288 
20289 /* This function is used to apply fixes to citations */
FixPubs(Uint2 entityID,Int4 iType,StringConstraintXPtr author_scp)20290 NLM_EXTERN void FixPubs (Uint2 entityID, Int4 iType, StringConstraintXPtr author_scp)
20291 {
20292   SeqEntryPtr  sep;
20293   SelStructPtr	sel;
20294   SeqFeatPtr	sfp;
20295   SeqMgrFeatContext fcontext;
20296   SeqDescPtr	sdp;
20297   SeqMgrDescContext dcontext;
20298   PubdescPtr	pdp;
20299   FixPubdescData fpd;
20300   SeqSubmitPtr   ssp;
20301 
20302   sep = GetTopSeqEntryForEntityID (entityID);
20303   if (iType & FIX_ALL)
20304   {
20305     sel = NULL;
20306   }
20307   else
20308   {
20309     sel = ObjMgrGetSelected ();
20310     if (!AreAnySelectedPubs(entityID, sel)) {
20311       sel = NULL;
20312     }
20313   }
20314 
20315   fpd.iType = iType;
20316   fpd.author_scp = author_scp;
20317 
20318   fpd.org_names = NULL;
20319   if (iType & FIX_PUB_TITLE_CAPITALIZATION)
20320   {
20321     VisitBioSourcesInSep (sep, &(fpd.org_names), GetOrgNamesInRecordCallback);
20322   }
20323 
20324   if(sel == NULL)
20325   {
20326     fpd.iType |= FIX_ALL;
20327     VisitPubdescsInSep (sep, (Pointer)&fpd, FixPubdesc);
20328     /* also fix Seq-submit block */
20329     ssp = FindSeqSubmitForSeqEntry (sep);
20330     if (ssp && ssp->sub != NULL && ssp->sub->cit != NULL && ssp->sub->cit->authors != NULL) {
20331       FixPubAuthors(ssp->sub->cit->authors, fpd.iType, fpd.author_scp);
20332     }
20333   }
20334   else
20335   {
20336     fpd.iType |= FIX_SELECTED;
20337     while( sel != NULL )
20338     {
20339       pdp = NULL;
20340       if(sel->entityID == entityID)
20341       {
20342         if(sel->itemtype == OBJ_SEQFEAT)
20343         {
20344           sfp = SeqMgrGetDesiredFeature (entityID, NULL, sel->itemID, 0, NULL, &fcontext);
20345           if(sfp != NULL && sfp->data.choice == SEQFEAT_PUB)
20346           {
20347             pdp = sfp->data.value.ptrvalue;
20348           }
20349         }
20350         else if(sel->itemtype == OBJ_SEQDESC)
20351         {
20352           sdp = SeqMgrGetDesiredDescriptor (entityID, NULL, sel->itemID, 0, NULL, &dcontext);
20353           if(sdp != NULL && sdp->choice == Seq_descr_pub)
20354           {
20355             pdp = sdp->data.ptrvalue;
20356           }
20357         }
20358       }
20359       if (pdp != NULL) FixPubdesc (pdp, (Pointer) &fpd);
20360       sel = sel->next;
20361     }
20362   }
20363 
20364   fpd.org_names = ValNodeFree (fpd.org_names);
20365 
20366   ObjMgrSetDirtyFlag (entityID, TRUE);
20367   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
20368   Update ();
20369 }
20370 
FixPubsMenuItem(IteM i,Int4 iType)20371 static void FixPubsMenuItem (IteM i, Int4 iType)
20372 {
20373   BaseFormPtr bfp;
20374 
20375 #ifdef WIN_MAC
20376   bfp = currentFormDataPtr;
20377 #else
20378   bfp = GetObjectExtra (i);
20379 #endif
20380 
20381   if (bfp == NULL) return;
20382   FixPubs (bfp->input_entityID, iType, NULL);
20383 }
20384 
20385 
FixPubsBtn(ButtoN b,Int4 iType)20386 static void FixPubsBtn (ButtoN b, Int4 iType)
20387 {
20388   BaseFormPtr bfp;
20389 
20390   bfp = (BaseFormPtr) GetObjectExtra (b);
20391   if (bfp == NULL) return;
20392   FixPubs (bfp->input_entityID, iType, NULL);
20393 }
20394 
20395 
FixPubCapsAuthor(ButtoN b)20396 static void FixPubCapsAuthor (ButtoN b)
20397 {
20398   FixPubsBtn (b, FIX_PUB_AUTHOR_CAPITALIZATION);
20399 }
20400 
20401 
FixPubCapsAffil(ButtoN b)20402 static void FixPubCapsAffil (ButtoN b)
20403 {
20404   FixPubsBtn (b, FIX_PUB_AFFIL_CAPITALIZATION);
20405 }
20406 
20407 
FixPubCapsTitle(ButtoN b)20408 static void FixPubCapsTitle (ButtoN b)
20409 {
20410   FixPubsBtn (b, FIX_PUB_TITLE_CAPITALIZATION);
20411 }
20412 
20413 
FixCapitalizationToolBtn(ButtoN b)20414 static void FixCapitalizationToolBtn (ButtoN b)
20415 {
20416   BaseFormPtr  bfp;
20417 
20418   bfp = (BaseFormPtr) GetObjectExtra (b);
20419   if (bfp == NULL) return;
20420   FixPubs (bfp->input_entityID, FIX_PUB_AUTHOR_CAPITALIZATION
20421               | FIX_PUB_TITLE_CAPITALIZATION
20422               | FIX_PUB_AFFIL_CAPITALIZATION
20423               | FIX_ALL,
20424               NULL);
20425 }
20426 
FixNameOrder(IteM i)20427 static void FixNameOrder (IteM i)
20428 {
20429   FixPubsMenuItem (i, FIX_AUTHOR_NAME_ORDER);
20430 }
20431 
20432 
RevAuthNamesBtn(ButtoN b)20433 static void RevAuthNamesBtn (ButtoN b)
20434 {
20435   BaseFormPtr           bfp;
20436 
20437 #ifdef WIN_MAC
20438   bfp = currentFormDataPtr;
20439 #else
20440   bfp = GetObjectExtra (b);
20441 #endif
20442 
20443   if (bfp == NULL) {
20444     return;
20445   }
20446   FixPubs (bfp->input_entityID, FIX_AUTHOR_NAME_ORDER, NULL);
20447   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
20448   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
20449   Update ();
20450 }
20451 
20452 
FixAllPubCapitalization(IteM i)20453 static void FixAllPubCapitalization (IteM i)
20454 {
20455   FixPubsMenuItem (i, FIX_PUB_AUTHOR_CAPITALIZATION | FIX_PUB_TITLE_CAPITALIZATION | FIX_PUB_AFFIL_CAPITALIZATION);
20456 }
20457 
FixAuthorCapitalization(IteM i)20458 static void FixAuthorCapitalization (IteM i)
20459 {
20460   FixPubsMenuItem (i, FIX_PUB_AUTHOR_CAPITALIZATION);
20461 }
20462 
20463 
TruncateAuthorMiddle(IteM i)20464 static void TruncateAuthorMiddle (IteM i)
20465 {
20466   FixPubsMenuItem (i, TRUNCATE_AUTHOR_MIDDLE_INITIALS);
20467 }
20468 
FixTitleCapitalization(IteM i)20469 static void FixTitleCapitalization (IteM i)
20470 {
20471   FixPubsMenuItem (i, FIX_PUB_TITLE_CAPITALIZATION);
20472 }
20473 
FixAffiliationCapitalization(IteM i)20474 static void FixAffiliationCapitalization (IteM i)
20475 {
20476   FixPubsMenuItem (i, FIX_PUB_AFFIL_CAPITALIZATION);
20477 }
20478 
FixPubCountryCapitalization(IteM i)20479 static void FixPubCountryCapitalization (IteM i)
20480 {
20481   FixPubsMenuItem (i, FIX_PUB_AFFIL_COUNTRY_CAPITALIZATION);
20482 }
20483 
StripAuthorSuffix(IteM i)20484 static void StripAuthorSuffix (IteM i)
20485 {
20486   FixPubsMenuItem (i, STRIP_AUTHOR_SUFFIX);
20487 }
20488 
ChangeAllAuthorNameToConsortium(IteM i)20489 static void ChangeAllAuthorNameToConsortium (IteM i)
20490 {
20491   FixPubsMenuItem (i, FIX_PUB_SWAP_NAME_CONSORTIUM);
20492 }
20493 
ChangeAuthorNameWithConsortiumToConsortium(IteM i)20494 static void ChangeAuthorNameWithConsortiumToConsortium (IteM i)
20495 {
20496   BaseFormPtr bfp;
20497   StringConstraintXPtr scp;
20498 
20499 #ifdef WIN_MAC
20500   bfp = currentFormDataPtr;
20501 #else
20502   bfp = GetObjectExtra (i);
20503 #endif
20504 
20505   if (bfp == NULL) return;
20506 
20507   scp = (StringConstraintXPtr) MemNew (sizeof (StringConstraintData));
20508   if (scp == NULL)
20509   {
20510     return;
20511   }
20512 
20513   scp->match_text = StringSave ("consortium");
20514   scp->match_location = eStringConstraintContains;
20515   scp->insensitive = TRUE;
20516   scp->whole_word = TRUE;
20517   scp->not_present = FALSE;
20518 
20519   FixPubs (bfp->input_entityID, FIX_PUB_SWAP_NAME_CONSORTIUM, scp);
20520   scp = StringConstraintXFree (scp);
20521 }
20522 
20523 typedef struct authornamestringconstraintform
20524 {
20525   FORM_MESSAGE_BLOCK
20526   DialoG author_name_constraint_dlg;
20527 } AuthorNameStringConstraintFormData, PNTR AuthorNameStringConstraintFormPtr;
20528 
DoChangeAuthorNameToConsortiumWithConstraint(ButtoN b)20529 static void DoChangeAuthorNameToConsortiumWithConstraint (ButtoN b)
20530 {
20531   AuthorNameStringConstraintFormPtr frm;
20532   StringConstraintXPtr               scp;
20533 
20534   frm = (AuthorNameStringConstraintFormPtr) GetObjectExtra (b);
20535   if (frm == NULL)
20536   {
20537     return;
20538   }
20539 
20540   scp = (StringConstraintXPtr) DialogToPointer (frm->author_name_constraint_dlg);
20541 
20542   Hide (frm->form);
20543   WatchCursor ();
20544   Update ();
20545 
20546   FixPubs (frm->input_entityID, FIX_PUB_SWAP_NAME_CONSORTIUM, scp);
20547   scp = StringConstraintXFree (scp);
20548   Remove ((WindoW)frm->form);
20549   ArrowCursor ();
20550   Update ();
20551 }
20552 
ChangeAuthorNameToConsortiumWithConstraint(IteM i)20553 static void ChangeAuthorNameToConsortiumWithConstraint (IteM i)
20554 {
20555   AuthorNameStringConstraintFormPtr frm;
20556   BaseFormPtr bfp;
20557   WindoW      w;
20558   GrouP       h, c;
20559   ButtoN      b;
20560 
20561 #ifdef WIN_MAC
20562   bfp = currentFormDataPtr;
20563 #else
20564   bfp = GetObjectExtra (i);
20565 #endif
20566 
20567   if (bfp == NULL) return;
20568 
20569   frm = (AuthorNameStringConstraintFormPtr) MemNew (sizeof (AuthorNameStringConstraintFormData));
20570   if (frm == NULL)
20571   {
20572     return;
20573   }
20574 
20575   w = FixedWindow (-50, -33, -10, -10, "Change Author Last Name to Consortium", StdCloseWindowProc);
20576   SetObjectExtra (w, frm, StdCleanupExtraProc);
20577   frm->form = (ForM) w;
20578   frm->input_entityID = bfp->input_entityID;
20579 
20580   h = HiddenGroup (w, -1, 0, NULL);
20581   SetGroupSpacing (h, 10, 10);
20582 
20583   frm->author_name_constraint_dlg =  StringConstraintDialogX (h, "Where author last name", TRUE);
20584 
20585   c = HiddenGroup (h, 2, 0, NULL);
20586   SetGroupSpacing (h, 10, 10);
20587 
20588   b = PushButton (c, "Accept", DoChangeAuthorNameToConsortiumWithConstraint);
20589   SetObjectExtra (b, frm, NULL);
20590 
20591   b = PushButton (c, "Cancel", StdCancelButtonProc);
20592 
20593   AlignObjects (ALIGN_CENTER, (HANDLE) frm->author_name_constraint_dlg,
20594                               (HANDLE) c,
20595                               NULL);
20596 
20597   Show (w);
20598 }
20599 
20600 
20601 
20602 
FixProductCapitalizationInString(CharPtr PNTR pStr,FixProductCapPtr fc)20603 NLM_EXTERN void FixProductCapitalizationInString (CharPtr PNTR pStr, FixProductCapPtr fc)
20604 {
20605   CharPtr cp, cp2;
20606 
20607   if (pStr == NULL || (cp = *pStr) == NULL || fc == NULL) {
20608     return;
20609   }
20610 
20611   /* first remove punctuation */
20612   if (fc->remove_list != NULL) {
20613     cp2 = cp + StringSpn (cp, fc->remove_list);
20614     while (*cp2 != 0) {
20615       if (cp2 != cp) {
20616         *cp = *cp2;
20617       }
20618       cp++;
20619       cp2 = cp2 + 1 + StringSpn (cp2 + 1, fc->remove_list);
20620     }
20621     *cp = 0;
20622   }
20623 
20624   /* now adjust capitalization */
20625   cp = *pStr;
20626   while (*cp != 0) {
20627     if (*cp == 'S' && cp > *pStr && IS_DIGIT (*(cp - 1))) {
20628       /* leave S after digits capitalized */
20629     } else if (*cp == 's' && cp > *pStr && IS_DIGIT (*(cp - 1))) {
20630       /* capitalize S after digits */
20631       *cp = 'S';
20632     } else if (IS_UPPER (*cp)) {
20633       if (fc->keep_cap_before_punct && ispunct (*(cp + 1))) {
20634         /* ok to leave as upper */
20635       } else if (fc->keep_cap_before_cap && IS_UPPER (*(cp + 1))) {
20636         /* ok to leave as upper, skip upper */
20637         while (IS_UPPER (*(cp + 1))) {
20638           cp++;
20639         }
20640       } else if (fc->keep_cap_before_digit && isdigit (*(cp + 1))) {
20641         /* ok to keep caps before numbers */
20642       } else {
20643         *cp = tolower (*cp);
20644       }
20645     }
20646     cp++;
20647   }
20648 
20649   FixAbbreviationsInElement (pStr);
20650   FixProductWordCapitalization(pStr);
20651 }
20652 
20653 
FixProductCapitalizationCallback(SeqFeatPtr sfp,Pointer userdata)20654 static void FixProductCapitalizationCallback (SeqFeatPtr sfp, Pointer userdata)
20655 {
20656   ProtRefPtr prp;
20657   RnaRefPtr  rrp;
20658   ValNodePtr vnp;
20659   CharPtr    product_name;
20660   RNAGenPtr  rgp;
20661 
20662   if (sfp == NULL) return;
20663   if (sfp->data.choice != SEQFEAT_PROT && sfp->data.choice != SEQFEAT_RNA) return;
20664 
20665   if (sfp->data.choice == SEQFEAT_PROT)
20666   {
20667     prp = (ProtRefPtr) sfp->data.value.ptrvalue;
20668     if (prp != NULL)
20669     {
20670       for (vnp = prp->name; vnp != NULL; vnp = vnp->next)
20671       {
20672         product_name = (CharPtr)(vnp->data.ptrvalue);
20673         FixProductCapitalizationInString (&product_name, (FixProductCapPtr) userdata);
20674         vnp->data.ptrvalue = product_name;
20675       }
20676     }
20677   }
20678   else if (sfp->data.choice == SEQFEAT_RNA)
20679   {
20680     rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
20681     if (rrp != NULL)
20682     {
20683       if (rrp->ext.choice == 1)
20684       {
20685         product_name = (CharPtr)(rrp->ext.value.ptrvalue);
20686         FixProductCapitalizationInString (&product_name, (FixProductCapPtr) userdata);
20687         rrp->ext.value.ptrvalue = product_name;
20688       }
20689       else if (rrp->ext.choice == 3 && (rgp = (RNAGenPtr) rrp->ext.value.ptrvalue) != NULL)
20690       {
20691         product_name = rgp->product;
20692         FixProductCapitalizationInString (&product_name, (FixProductCapPtr) userdata);
20693         rgp->product = product_name;
20694       }
20695     }
20696   }
20697 }
20698 
20699 typedef struct fixproductcapdlg {
20700   FORM_MESSAGE_BLOCK
20701   ButtoN keep_cap_before_punct;
20702   ButtoN keep_cap_before_cap;
20703   ButtoN keep_cap_before_digit;
20704   ButtoN remove_comma;
20705 } FixProductCapDlgData, PNTR FixProductCapDlgPtr;
20706 
20707 
DoFixProductCapitalization(ButtoN b)20708 static void DoFixProductCapitalization (ButtoN b)
20709 {
20710   FixProductCapDlgPtr dlg;
20711   FixProductCapData   data;
20712   SeqEntryPtr       sep;
20713   SelStructPtr      sel;
20714   Boolean           any_found = FALSE;
20715   SeqMgrFeatContext fcontext;
20716   SeqFeatPtr        sfp;
20717   RnaRefPtr         rrp;
20718 
20719   dlg = (FixProductCapDlgPtr) GetObjectExtra (b);
20720   if (dlg == NULL) {
20721     return;
20722   }
20723 
20724   sep = GetTopSeqEntryForEntityID (dlg->input_entityID);
20725 
20726   MemSet (&data, 0, sizeof (FixProductCapData));
20727   data.keep_cap_before_cap = GetStatus (dlg->keep_cap_before_cap);
20728   data.keep_cap_before_punct = GetStatus (dlg->keep_cap_before_punct);
20729   data.keep_cap_before_digit = GetStatus (dlg->keep_cap_before_digit);
20730   if (GetStatus (dlg->remove_comma)) {
20731     data.remove_list = (CharPtr) MemNew (sizeof (Char) * 2);
20732     sprintf (data.remove_list, ",");
20733   }
20734 
20735   sel = ObjMgrGetSelected ();
20736   if(sel == NULL)
20737   {
20738     VisitFeaturesInSep (sep, &data, FixProductCapitalizationCallback);
20739   }
20740   else
20741   {
20742     while( sel != NULL )
20743     {
20744       if(sel->entityID == dlg->input_entityID && sel->itemtype == OBJ_SEQFEAT)
20745       {
20746         sfp = SeqMgrGetDesiredFeature (dlg->input_entityID, NULL, sel->itemID, 0, NULL, &fcontext);
20747         if(sfp != NULL)
20748         {
20749           if (sfp->data.choice == SEQFEAT_PROT)
20750           {
20751           	FixProductCapitalizationCallback (sfp, &data);
20752           	any_found = TRUE;
20753           }
20754           else if (sfp->data.choice == SEQFEAT_RNA)
20755           {
20756             rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
20757           	if (rrp != NULL && rrp->ext.choice == 1)
20758           	{
20759           	  FixProductCapitalizationCallback (sfp, &data);
20760           	  any_found = TRUE;
20761           	}
20762           }
20763         }
20764       }
20765       sel = sel->next;
20766     }
20767     if (!any_found)
20768     {
20769       VisitFeaturesInSep (sep, &data, FixProductCapitalizationCallback);
20770     }
20771   }
20772 
20773   data.remove_list = MemFree (data.remove_list);
20774 
20775   ObjMgrSetDirtyFlag (dlg->input_entityID, TRUE);
20776   ObjMgrSendMsg (OM_MSG_UPDATE, dlg->input_entityID, 0, 0);
20777   Remove (dlg->form);
20778   Update ();
20779 }
20780 
20781 
FixProductCapitalization(IteM i)20782 static void FixProductCapitalization (IteM i)
20783 {
20784   BaseFormPtr         bfp;
20785   FixProductCapDlgPtr dlg;
20786   WindoW      w;
20787   GrouP       h, g, c;
20788   ButtoN      b;
20789 
20790 #ifdef WIN_MAC
20791   bfp = currentFormDataPtr;
20792 #else
20793   bfp = GetObjectExtra (i);
20794 #endif
20795 
20796   if (bfp == NULL) return;
20797 
20798   dlg = (FixProductCapDlgPtr) MemNew (sizeof (FixProductCapDlgData));
20799   if (dlg == NULL)
20800   {
20801     return;
20802   }
20803 
20804   w = FixedWindow (-50, -33, -10, -10, "Fix Product Name Capitalization", StdCloseWindowProc);
20805   SetObjectExtra (w, dlg, StdCleanupExtraProc);
20806   dlg->form = (ForM) w;
20807   dlg->input_entityID = bfp->input_entityID;
20808 
20809   h = HiddenGroup (w, -1, 0, NULL);
20810   SetGroupSpacing (h, 10, 10);
20811 
20812   g = HiddenGroup (h, 0, 4, NULL);
20813   SetGroupSpacing (g, 10, 10);
20814   dlg->keep_cap_before_punct = CheckBox (g, "Keep caps before punctuation", NULL);
20815   dlg->keep_cap_before_cap = CheckBox (g, "Keep caps before caps", NULL);
20816   dlg->keep_cap_before_digit = CheckBox (g, "Keep caps before numbers", NULL);
20817   dlg->remove_comma = CheckBox (g, "Remove comma", NULL);
20818 
20819   c = HiddenGroup (h, 2, 0, NULL);
20820   SetGroupSpacing (h, 10, 10);
20821 
20822   b = PushButton (c, "Accept", DoFixProductCapitalization);
20823   SetObjectExtra (b, dlg, NULL);
20824 
20825   b = PushButton (c, "Cancel", StdCancelButtonProc);
20826 
20827   AlignObjects (ALIGN_CENTER, (HANDLE) g,
20828                               (HANDLE) c,
20829                               NULL);
20830 
20831   Show (w);
20832 }
20833 
FixProductCapitalizationDefault(IteM i)20834 static void FixProductCapitalizationDefault (IteM i)
20835 {
20836   BaseFormPtr         bfp;
20837   FixProductCapData   data;
20838   SeqEntryPtr         sep;
20839   SelStructPtr        sel;
20840   Boolean             any_found = FALSE;
20841   SeqMgrFeatContext   fcontext;
20842   SeqFeatPtr          sfp;
20843   RnaRefPtr           rrp;
20844 
20845 #ifdef WIN_MAC
20846   bfp = currentFormDataPtr;
20847 #else
20848   bfp = GetObjectExtra (i);
20849 #endif
20850 
20851   if (bfp == NULL) return;
20852 
20853   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
20854   MemSet (&data, 0, sizeof (FixProductCapData));
20855 
20856   sel = ObjMgrGetSelected ();
20857   if(sel == NULL)
20858   {
20859     VisitFeaturesInSep (sep, &data, FixProductCapitalizationCallback);
20860   }
20861   else
20862   {
20863     while( sel != NULL )
20864     {
20865       if(sel->entityID == bfp->input_entityID && sel->itemtype == OBJ_SEQFEAT)
20866       {
20867         sfp = SeqMgrGetDesiredFeature (bfp->input_entityID, NULL, sel->itemID, 0, NULL, &fcontext);
20868         if(sfp != NULL)
20869         {
20870           if (sfp->data.choice == SEQFEAT_PROT)
20871           {
20872           	FixProductCapitalizationCallback (sfp, &data);
20873           	any_found = TRUE;
20874           }
20875           else if (sfp->data.choice == SEQFEAT_RNA)
20876           {
20877             rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
20878           	if (rrp != NULL && rrp->ext.choice == 1)
20879           	{
20880           	  FixProductCapitalizationCallback (sfp, &data);
20881           	  any_found = TRUE;
20882           	}
20883           }
20884         }
20885       }
20886       sel = sel->next;
20887     }
20888     if (!any_found)
20889     {
20890       VisitFeaturesInSep (sep, &data, FixProductCapitalizationCallback);
20891     }
20892   }
20893 
20894   data.remove_list = MemFree (data.remove_list);
20895 
20896   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
20897   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
20898   Update ();
20899 }
20900 
20901 
FixDeltaSeqDataLenCallback(BioseqPtr bsp,Pointer userdata)20902 static void FixDeltaSeqDataLenCallback (BioseqPtr bsp, Pointer userdata)
20903 {
20904   DeltaSeqPtr dsp;
20905   SeqLocPtr   slp;
20906   SeqLitPtr   slip;
20907   Int4        bsp_len = 0;
20908 
20909   if (bsp == NULL || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4)
20910   {
20911     return;
20912   }
20913 
20914   dsp = (DeltaSeqPtr) bsp->seq_ext;
20915   while (dsp != NULL)
20916   {
20917     if (dsp->choice == 2)
20918     {
20919       slip = (SeqLitPtr) dsp->data.ptrvalue;
20920       bsp_len += slip->length;
20921     }
20922     else if (dsp->choice == 1)
20923     {
20924       slp = (SeqLocPtr) dsp->data.ptrvalue;
20925       bsp_len += SeqLocLen (slp);
20926     }
20927     dsp = dsp->next;
20928   }
20929   bsp->length = bsp_len;
20930 }
20931 
FixDeltaSeqDataLen(IteM i)20932 static void FixDeltaSeqDataLen (IteM i)
20933 {
20934   BaseFormPtr  bfp;
20935   SeqEntryPtr  sep;
20936 
20937 #ifdef WIN_MAC
20938   bfp = currentFormDataPtr;
20939 #else
20940   bfp = GetObjectExtra (i);
20941 #endif
20942   if (bfp == NULL) return;
20943 
20944   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
20945   VisitBioseqsInSep (sep, NULL, FixDeltaSeqDataLenCallback);
20946   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
20947   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
20948   Update ();
20949 }
20950 
InstantiateGapFeatCallback(BioseqPtr bsp,Pointer userdata)20951 static void InstantiateGapFeatCallback (BioseqPtr bsp, Pointer userdata)
20952 
20953 {
20954   Char        buf [32];
20955   Int4        currpos = 0;
20956   IntFuzzPtr  fuzz;
20957   ImpFeatPtr  ifp;
20958   SeqLitPtr   litp;
20959   SeqFeatPtr  sfp;
20960   SeqIdPtr    sip;
20961   SeqLocPtr   slp;
20962   ValNodePtr  vnp;
20963 
20964   if (bsp == NULL || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4) return;
20965   sip = SeqIdFindBest (bsp->id, 0);
20966   if (sip == NULL) return;
20967   /* suppress on far delta contigs for now */
20968   if (! DeltaLitOnly (bsp)) return;
20969 
20970   for (vnp = (ValNodePtr)(bsp->seq_ext); vnp != NULL; vnp = vnp->next) {
20971     if (vnp->choice == 1) {
20972       slp = (SeqLocPtr) vnp->data.ptrvalue;
20973       if (slp == NULL) continue;
20974       currpos += SeqLocLen (slp);
20975     }
20976     if (vnp->choice == 2) {
20977       litp = (SeqLitPtr) vnp->data.ptrvalue;
20978       if (litp == NULL) continue;
20979       if (IsDeltaSeqGap (vnp) && litp->length > 0) {
20980         ifp = ImpFeatNew ();
20981         if (ifp == NULL) continue;
20982         ifp->key = StringSave ("gap");
20983         fuzz = litp->fuzz;
20984         sfp = CreateNewFeatureOnBioseq (bsp, SEQFEAT_IMP, NULL);
20985         if (sfp == NULL) continue;
20986         sfp->data.choice = SEQFEAT_IMP;
20987         sfp->data.value.ptrvalue = (Pointer) ifp;
20988         if (IsDeltaSeqUnknownGap (vnp)) {
20989           AddQualifierToFeature (sfp, "estimated_length", "unknown");
20990           sfp->location = SeqLocFree (sfp->location);
20991           sfp->location = AddIntervalToLocation (NULL, sip, currpos, currpos + litp->length - 1, FALSE, FALSE);
20992         } else {
20993           sprintf (buf, "%ld", (long) litp->length);
20994           AddQualifierToFeature (sfp, "estimated_length", buf);
20995           sfp->location = SeqLocFree (sfp->location);
20996           sfp->location = AddIntervalToLocation (NULL, sip, currpos, currpos + litp->length - 1, FALSE, FALSE);
20997         }
20998       }
20999       currpos += litp->length;
21000     }
21001   }
21002 }
21003 
InstantiateGapFeatures(IteM i)21004 static void InstantiateGapFeatures (IteM i)
21005 
21006 {
21007   BaseFormPtr  bfp;
21008   SeqEntryPtr  sep;
21009 
21010 #ifdef WIN_MAC
21011   bfp = currentFormDataPtr;
21012 #else
21013   bfp = GetObjectExtra (i);
21014 #endif
21015   if (bfp == NULL) return;
21016 
21017   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21018   VisitBioseqsInSep (sep, NULL, InstantiateGapFeatCallback);
21019   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21020   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21021   Update ();
21022 }
21023 
21024 
RenormalizeNucProtSetsMenuItem(IteM i)21025 static void RenormalizeNucProtSetsMenuItem (IteM i)
21026 {
21027   BaseFormPtr  bfp;
21028   SeqEntryPtr  sep;
21029 
21030   /* Get the current data */
21031 
21032 #ifdef WIN_MAC
21033   bfp = currentFormDataPtr;
21034 #else
21035   bfp = GetObjectExtra (i);
21036 #endif
21037 
21038   if (bfp == NULL)
21039     return;
21040 
21041   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21042   if (sep == NULL) return;
21043   WatchCursor();
21044   Update();
21045   RenormalizeNucProtSets (sep, TRUE);
21046 
21047   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21048   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21049   ArrowCursor ();
21050   Update ();
21051 
21052   /* Return successfully */
21053 
21054   return;
21055 }
21056 
21057 
AddAllDbxrefsBioseqCallback(BioseqPtr bsp,Pointer data)21058 static void AddAllDbxrefsBioseqCallback (BioseqPtr bsp, Pointer data)
21059 {
21060   AddAllDbxrefsToBioseq (bsp);
21061 }
21062 
21063 
AddAllDbxrefsMenuItem(IteM i)21064 static void AddAllDbxrefsMenuItem (IteM i)
21065 {
21066   BaseFormPtr  bfp;
21067   SeqEntryPtr  sep;
21068 
21069   /* Get the current data */
21070 
21071 #ifdef WIN_MAC
21072   bfp = currentFormDataPtr;
21073 #else
21074   bfp = GetObjectExtra (i);
21075 #endif
21076 
21077   if (bfp == NULL)
21078     return;
21079 
21080   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21081 
21082   VisitBioseqsInSep (sep, NULL, AddAllDbxrefsBioseqCallback);
21083   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21084   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21085 }
21086 
21087 extern void ResolveExistingLocalIDs (IteM i);
21088 extern void SetSourceFocus (IteM i);
21089 extern void ClearSourceFocus (IteM i);
21090 extern void FuseSlpJoins (IteM i);
21091 extern void AddGlobalCodeBreak (IteM i);
21092 extern void ParseTrinomial (IteM i);
21093 extern void EditSeqEndsProc (IteM i);
21094 
NewAligmentViewer(IteM i)21095 static void NewAligmentViewer (IteM i)
21096 {
21097   BaseFormPtr  bfp;
21098   BioseqPtr    bsp;
21099   ValNodePtr   seq_annot_list;
21100   SeqAnnotPtr  sap;
21101   SeqAlignPtr  salp = NULL;
21102 
21103 #ifdef WIN_MAC
21104   bfp = currentFormDataPtr;
21105 #else
21106   bfp = GetObjectExtra (i);
21107 #endif
21108 
21109   if (bfp == NULL) return;
21110 
21111   bsp = GetBioseqGivenIDs (bfp->input_entityID,
21112                            bfp->input_itemID,
21113                            bfp->input_itemtype);
21114   if (bsp == NULL) return;
21115   seq_annot_list = FindAlignSeqAnnotsForBioseq (bsp);
21116   if (seq_annot_list != NULL && seq_annot_list->data.ptrvalue != NULL)
21117   {
21118     sap = (SeqAnnotPtr) seq_annot_list->data.ptrvalue;
21119     if (sap->type == 2)
21120     {
21121       salp = (SeqAlignPtr) sap->data;
21122     }
21123   }
21124   if (salp == NULL)
21125   {
21126     Message (MSG_ERROR, "No alignments found for this Bioseq!");
21127     return;
21128   }
21129 
21130   OpenNewAlignmentEditor (salp, bfp->input_entityID);
21131 
21132 }
21133 
ShowDiscrepancyReport(IteM i)21134 static void ShowDiscrepancyReport (IteM i)
21135 {
21136   BaseFormPtr  bfp;
21137 #ifdef WIN_MAC
21138   bfp = currentFormDataPtr;
21139 #else
21140   bfp = GetObjectExtra (i);
21141 #endif
21142 
21143   if (bfp == NULL) return;
21144 
21145   CreateReportWindow (eReportTypeDiscrepancy);
21146 }
21147 
ShowOnCallerTool(IteM i)21148 static void ShowOnCallerTool (IteM i)
21149 {
21150   BaseFormPtr  bfp;
21151 #ifdef WIN_MAC
21152   bfp = currentFormDataPtr;
21153 #else
21154   bfp = GetObjectExtra (i);
21155 #endif
21156 
21157   if (bfp == NULL) return;
21158 
21159   CreateReportWindow (eReportTypeOnCaller);
21160 }
21161 
ShowMegaReport(IteM i)21162 static void ShowMegaReport (IteM i)
21163 {
21164   BaseFormPtr  bfp;
21165 #ifdef WIN_MAC
21166   bfp = currentFormDataPtr;
21167 #else
21168   bfp = GetObjectExtra (i);
21169 #endif
21170 
21171   if (bfp == NULL) return;
21172 
21173   CreateReportWindow (eReportTypeMegaReport);
21174 }
21175 
TestTax3(IteM i,Int4 taxid,CharPtr name)21176 static void TestTax3 (IteM i, Int4 taxid, CharPtr name)
21177 
21178 {
21179   BaseFormPtr       bfp;
21180   OrgNamePtr        onp;
21181   OrgRefPtr         orp;
21182   T3DataPtr         tdp;
21183   T3ErrorPtr        tep;
21184   Taxon3RequestPtr  t3rq;
21185   Taxon3ReplyPtr    t3ry;
21186   T3ReplyPtr        trp;
21187 
21188 #ifdef WIN_MAC
21189   bfp = currentFormDataPtr;
21190 #else
21191   bfp = GetObjectExtra (i);
21192 #endif
21193   if (bfp == NULL) return;
21194 
21195   t3rq = CreateTaxon3Request (taxid, name, NULL);
21196   if (t3rq == NULL) return;
21197   t3ry = Tax3SynchronousQuery (t3rq);
21198   Taxon3RequestFree (t3rq);
21199   if (t3ry != NULL) {
21200     for (trp = t3ry->reply; trp != NULL; trp = trp->next) {
21201       switch (trp->choice) {
21202         case T3Reply_error :
21203           tep = (T3ErrorPtr) trp->data.ptrvalue;
21204           if (tep != NULL) {
21205             Message (MSG_POST, "T3 error %s", tep->message);
21206           }
21207           break;
21208         case T3Reply_data :
21209           tdp = (T3DataPtr) trp->data.ptrvalue;
21210           if (tdp != NULL) {
21211             orp = (OrgRefPtr) tdp->org;
21212             if (orp != NULL) {
21213               onp = orp->orgname;
21214               if (onp != NULL) {
21215                 Message (MSG_POST, "T3 data %s code %d", orp->taxname, (int) onp->gcode);
21216               }
21217             }
21218           }
21219           break;
21220         default :
21221           break;
21222       }
21223     }
21224     Taxon3ReplyFree (t3ry);
21225   }
21226 }
21227 
TestTax3A(IteM i)21228 static void TestTax3A (IteM i)
21229 
21230 {
21231   TestTax3 (i, 9606, NULL);
21232 }
21233 
TestTax3B(IteM i)21234 static void TestTax3B (IteM i)
21235 
21236 {
21237   TestTax3 (i, 0, "Escherichia coli");
21238 }
21239 
MarkOrphanedProteins(BioseqPtr bsp,Pointer userdata)21240 static void MarkOrphanedProteins (BioseqPtr bsp, Pointer userdata)
21241 
21242 {
21243   SeqFeatPtr         cds;
21244   SeqMgrFeatContext  context;
21245 
21246   if (bsp == NULL) return;
21247   if (! ISA_aa (bsp->mol)) return;
21248 
21249   cds = SeqMgrGetCDSgivenProduct (bsp, &context);
21250   if (cds == NULL) {
21251     bsp->idx.deleteme = TRUE;
21252   }
21253 }
21254 
RemoveOrphanedProteins(IteM i)21255 static void RemoveOrphanedProteins (IteM i)
21256 
21257 {
21258   BaseFormPtr  bfp;
21259   SeqEntryPtr  sep;
21260 
21261 #ifdef WIN_MAC
21262   bfp = currentFormDataPtr;
21263 #else
21264   bfp = GetObjectExtra (i);
21265 #endif
21266   if (bfp == NULL) return;
21267   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21268   if (sep == NULL) return;
21269 
21270   VisitBioseqsInSep (sep, NULL, MarkOrphanedProteins);
21271 
21272   DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
21273   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21274   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21275 }
21276 
ViewSortedProteinMenuItem(IteM i)21277 static void ViewSortedProteinMenuItem(IteM i)
21278 {
21279   BaseFormPtr  bfp;
21280   SeqEntryPtr  sep;
21281 
21282 #ifdef WIN_MAC
21283   bfp = currentFormDataPtr;
21284 #else
21285   bfp = GetObjectExtra (i);
21286 #endif
21287   if (bfp == NULL) return;
21288   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21289   if (sep == NULL) return;
21290   ViewSortedProteins(sep);
21291 }
21292 
21293 
ApplyBarcodeDbxrefs(IteM i)21294 static void ApplyBarcodeDbxrefs (IteM i)
21295 {
21296   BaseFormPtr  bfp;
21297   SeqEntryPtr  sep;
21298 
21299 #ifdef WIN_MAC
21300   bfp = currentFormDataPtr;
21301 #else
21302   bfp = GetObjectExtra (i);
21303 #endif
21304   if (bfp == NULL) return;
21305   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21306   if (sep == NULL) return;
21307 
21308   VisitBioseqsInSep (sep, NULL, ApplyBarcodeDbxrefsToBioseq);
21309 
21310   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21311   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21312   Update();
21313 }
21314 
21315 
ApplyFBOLDbxrefs(IteM i)21316 static void ApplyFBOLDbxrefs (IteM i)
21317 {
21318   BaseFormPtr  bfp;
21319   SeqEntryPtr  sep;
21320 
21321 #ifdef WIN_MAC
21322   bfp = currentFormDataPtr;
21323 #else
21324   bfp = GetObjectExtra (i);
21325 #endif
21326   if (bfp == NULL) return;
21327   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21328   if (sep == NULL) return;
21329 
21330   VisitBioseqsInSep (sep, NULL, ApplyFBOLDbxrefsToBioseq);
21331 
21332   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21333   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21334   Update();
21335 }
21336 
21337 
ModPCRCallback(BioSourcePtr biop,Pointer userdata)21338 static void ModPCRCallback (BioSourcePtr biop, Pointer userdata)
21339 
21340 {
21341   ModernizePCRPrimers (biop);
21342 }
21343 
ModernizePCRs(IteM i)21344 static void ModernizePCRs (IteM i)
21345 
21346 {
21347   BaseFormPtr  bfp;
21348   SeqEntryPtr  sep;
21349 
21350 #ifdef WIN_MAC
21351   bfp = currentFormDataPtr;
21352 #else
21353   bfp = GetObjectExtra (i);
21354 #endif
21355   if (bfp == NULL) return;
21356   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21357   if (sep == NULL) return;
21358 
21359   VisitBioSourcesInSep (sep, NULL, ModPCRCallback);
21360 
21361   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21362   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21363 }
21364 
ModRNACallback(SeqFeatPtr sfp,Pointer userdata)21365 static void ModRNACallback (SeqFeatPtr sfp, Pointer userdata)
21366 
21367 {
21368   ModernizeRNAFields (sfp);
21369 }
21370 
ModernizeRNAs(IteM i)21371 static void ModernizeRNAs (IteM i)
21372 
21373 {
21374   BaseFormPtr  bfp;
21375   SeqEntryPtr  sep;
21376 
21377 #ifdef WIN_MAC
21378   bfp = currentFormDataPtr;
21379 #else
21380   bfp = GetObjectExtra (i);
21381 #endif
21382   if (bfp == NULL) return;
21383   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21384   if (sep == NULL) return;
21385 
21386   VisitFeaturesInSep (sep, NULL, ModRNACallback);
21387 
21388   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21389   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21390 }
21391 
ModGeneCallback(SeqFeatPtr sfp,Pointer userdata)21392 static void ModGeneCallback (SeqFeatPtr sfp, Pointer userdata)
21393 
21394 {
21395   ModernizeGeneFields (sfp);
21396 }
21397 
ModernizeGenes(IteM i)21398 static void ModernizeGenes (IteM i)
21399 
21400 {
21401   BaseFormPtr  bfp;
21402   SeqEntryPtr  sep;
21403 
21404 #ifdef WIN_MAC
21405   bfp = currentFormDataPtr;
21406 #else
21407   bfp = GetObjectExtra (i);
21408 #endif
21409   if (bfp == NULL) return;
21410   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21411   if (sep == NULL) return;
21412 
21413   VisitFeaturesInSep (sep, NULL, ModGeneCallback);
21414 
21415   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21416   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21417 }
21418 
GI2dbSTSCallback(SeqFeatPtr sfp,Pointer userdata)21419 static void GI2dbSTSCallback (SeqFeatPtr sfp, Pointer userdata)
21420 
21421 {
21422   BioseqPtr    bsp;
21423   Char         buf [64];
21424   DbtagPtr     dbt;
21425   ImpFeatPtr   ifp;
21426   MolInfoPtr   mip;
21427   ObjectIdPtr  oip;
21428   SeqDescrPtr  sdp;
21429   SeqId        si;
21430   SeqIdPtr     sip;
21431   Int4         uid;
21432   ValNodePtr   vnp;
21433 
21434   if (sfp == NULL || sfp->data.choice != SEQFEAT_IMP) return;
21435   ifp = (ImpFeatPtr) sfp->data.value.ptrvalue;
21436   if (ifp == NULL || StringICmp (ifp->key, "STS") != 0) return;
21437   for (vnp = sfp->dbxref; vnp != NULL; vnp = vnp->next) {
21438     dbt = (DbtagPtr) vnp->data.ptrvalue;
21439     if (dbt == NULL) continue;
21440     if (StringICmp (dbt->db, "GI") != 0) continue;
21441     oip = dbt->tag;
21442     if (oip == NULL) continue;
21443     if (oip->str != NULL) continue;
21444     uid = oip->id;
21445     if (uid < 1) continue;
21446     MemSet ((Pointer) &si, 0, sizeof (SeqId));
21447     si.choice = SEQID_GI;
21448     si.data.intvalue = uid;
21449     bsp = BioseqLockById (&si);
21450     if (bsp == NULL) continue;
21451     sdp = GetNextDescriptorUnindexed (bsp, Seq_descr_molinfo, NULL);
21452     if (sdp != NULL && sdp->choice == Seq_descr_molinfo) {
21453       mip = (MolInfoPtr) sdp->data.ptrvalue;
21454       if (mip != NULL) {
21455         if (mip->tech == MI_TECH_sts) {
21456           sip = GetSeqIdForGI (uid);
21457           if (sip != NULL) {
21458             SeqIdWrite (sip, buf, PRINTID_TEXTID_ACC_ONLY, sizeof (buf) - 1);
21459             SeqIdFree (sip);
21460             if (StringDoesHaveText (buf)) {
21461               dbt->db = MemFree (dbt->db);
21462               dbt->db = StringSave ("dbSTS");
21463               oip->id = 0;
21464               oip->str = StringSave (buf);
21465             }
21466           }
21467         } else {
21468           Message (MSG_POST, "Tech for gi %ld is %d", (long) uid, (int) mip->tech);
21469         }
21470       }
21471     }
21472     BioseqUnlock (bsp);
21473   }
21474 }
21475 
DoGI2dbSTSConversion(IteM i)21476 static void DoGI2dbSTSConversion (IteM i)
21477 
21478 {
21479   BaseFormPtr  bfp;
21480   SeqEntryPtr  sep;
21481 
21482 #ifdef WIN_MAC
21483   bfp = currentFormDataPtr;
21484 #else
21485   bfp = GetObjectExtra (i);
21486 #endif
21487   if (bfp == NULL) return;
21488   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21489   if (sep == NULL) return;
21490 
21491   VisitFeaturesInSep (sep, NULL, GI2dbSTSCallback);
21492 
21493   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21494   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21495 }
21496 
21497 
21498 typedef struct splitqual {
21499   ValNodePtr qual_list;
21500   CharPtr delimiter;
21501 } SplitQualData, PNTR SplitQualPtr;
21502 
21503 
RemoveSurroundParens(CharPtr str)21504 static void RemoveSurroundParens (CharPtr str)
21505 {
21506   Int4 len;
21507   CharPtr src, dst;
21508 
21509   if (StringHasNoText (str)) {
21510     return;
21511   }
21512 
21513   if (str[0] == '(') {
21514     len = StringLen (str + 1);
21515     if (str[len] == ')' && StringCSpn (str + 1, "()") == len - 1) {
21516       src = str + 1;
21517       dst = str;
21518       while (*src != ')') {
21519         *dst = *src;
21520         ++dst;
21521         ++src;
21522       }
21523       *dst = 0;
21524     }
21525   }
21526 }
21527 
21528 
SplitQualCallback(BioSourcePtr biop,Pointer userdata)21529 static void SplitQualCallback (BioSourcePtr biop, Pointer userdata)
21530 {
21531   SplitQualPtr s;
21532   ValNodePtr   qual, vnp;
21533   CharPtr      val, cp, start;
21534   StringConstraintPtr scp_find, scp_remove;
21535   ValNodePtr          existing_vals = NULL;
21536 
21537   if (biop == NULL || (s = (SplitQualPtr) userdata) == NULL) {
21538     return;
21539   }
21540 
21541   scp_find = StringConstraintNew ();
21542   scp_find->match_location = String_location_contains;
21543   scp_find->match_text = s->delimiter;
21544   scp_remove = StringConstraintNew ();
21545   scp_remove->case_sensitive = TRUE;
21546   scp_remove->match_location = String_location_equals;
21547 
21548   for (qual = s->qual_list; qual != NULL; qual = qual->next) {
21549     val = GetSourceQualFromBioSource (biop, qual, scp_find);
21550     while (val != NULL) {
21551       scp_remove->match_text = val;
21552       if (RemoveSourceQualFromBioSource (biop, qual, scp_remove)) {
21553         ValNodeAddPointer (&existing_vals, 0, val);
21554         val = GetSourceQualFromBioSource (biop, qual, scp_find);
21555       } else {
21556         val = NULL;
21557       }
21558       scp_remove->match_text = NULL;
21559     }
21560     for (vnp = existing_vals; vnp != NULL; vnp = vnp->next) {
21561       start = vnp->data.ptrvalue;
21562       RemoveSurroundParens (start);
21563       while (start != NULL && *start != 0) {
21564         cp = StringStr (start, s->delimiter);
21565         if (cp != NULL) {
21566           *cp = 0;
21567         }
21568         SetSourceQualInBioSource (biop, qual, NULL, start, ExistingTextOption_add_qual);
21569         if (cp == NULL) {
21570           start = NULL;
21571         } else {
21572           start = cp + StringLen (s->delimiter);
21573         }
21574       }
21575     }
21576     existing_vals = ValNodeFree (existing_vals);
21577   }
21578   scp_remove->match_text = NULL;
21579   scp_remove = StringConstraintFree (scp_remove);
21580   scp_find->match_text = NULL;
21581   scp_find = StringConstraintFree (scp_find);
21582 }
21583 
21584 
SplitQualsAtCommas(IteM i)21585 static void SplitQualsAtCommas (IteM i)
21586 
21587 {
21588   BaseFormPtr  bfp;
21589   SeqEntryPtr  sep;
21590   SplitQualData s;
21591 
21592 #ifdef WIN_MAC
21593   bfp = currentFormDataPtr;
21594 #else
21595   bfp = GetObjectExtra (i);
21596 #endif
21597   if (bfp == NULL) return;
21598   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21599   if (sep == NULL) return;
21600 
21601   s.delimiter = ",";
21602   s.qual_list = ValNodeNew (NULL);
21603   s.qual_list->choice = SourceQualChoice_textqual;
21604   s.qual_list->data.intvalue = Source_qual_strain;
21605 
21606   VisitBioSourcesInSep (sep, &s, SplitQualCallback);
21607 
21608   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21609   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21610 }
21611 
21612 
SplitDBLinkCallback(SeqDescPtr sdp,Pointer data)21613 static void SplitDBLinkCallback (SeqDescPtr sdp, Pointer data)
21614 {
21615   CharPtr       cp, start;
21616   ValNodePtr    new_vals = NULL, vnp;
21617   UserObjectPtr uop;
21618   UserFieldPtr  curr;
21619   Boolean       any = FALSE;
21620   CharPtr PNTR  cpp;
21621   Int4          i;
21622 
21623   if (sdp == NULL
21624       || sdp->choice != Seq_descr_user
21625       || (uop = (UserObjectPtr)sdp->data.ptrvalue) == NULL
21626       || uop->type == NULL
21627       || StringCmp (uop->type->str, "DBLink") != 0) {
21628     return;
21629   }
21630 
21631   for (curr = uop->data; curr != NULL; curr = curr->next) {
21632     if (curr->choice == 7 && curr->num > 0 && (cpp = (CharPtr PNTR) curr->data.ptrvalue) != NULL) {
21633       for (i = 0; i < curr->num; i++) {
21634         cp = StringChr (cpp[i], ',');
21635         if (cp == NULL) {
21636           ValNodeAddPointer (&new_vals, 0, StringSave (cpp[i]));
21637         } else {
21638           any = TRUE;
21639           start = cpp[i];
21640           while (cp != NULL) {
21641             *cp = 0;
21642             if (!StringHasNoText (start)) {
21643               ValNodeAddPointer (&new_vals, 0, StringSave (start));
21644             }
21645             start = cp + 1;
21646             cp = StringChr (start, ',');
21647           }
21648           if (!StringHasNoText (start)) {
21649             ValNodeAddPointer (&new_vals, 0, StringSave (start));
21650           }
21651         }
21652       }
21653       if (any) {
21654         for (i = 0; i < curr->num; i++) {
21655           cpp[i] = MemFree (cpp[i]);
21656         }
21657         cpp = MemFree (cpp);
21658         curr->num = ValNodeLen (new_vals);
21659         cpp = (CharPtr PNTR) MemNew (sizeof (CharPtr) * curr->num);
21660         for (i = 0, vnp = new_vals; i < curr->num && vnp != NULL; i++, vnp = vnp->next) {
21661           cpp[i] = vnp->data.ptrvalue;
21662           vnp->data.ptrvalue = NULL;
21663         }
21664         curr->data.ptrvalue = cpp;
21665       }
21666       new_vals = ValNodeFreeData (new_vals);
21667     }
21668   }
21669 }
21670 
21671 
SplitDBLinkFieldsAtCommas(IteM i)21672 static void SplitDBLinkFieldsAtCommas (IteM i)
21673 
21674 {
21675   BaseFormPtr  bfp;
21676   SeqEntryPtr  sep;
21677 
21678 #ifdef WIN_MAC
21679   bfp = currentFormDataPtr;
21680 #else
21681   bfp = GetObjectExtra (i);
21682 #endif
21683   if (bfp == NULL) return;
21684   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21685   if (sep == NULL) return;
21686 
21687   VisitDescriptorsInSep (sep, NULL, SplitDBLinkCallback);
21688 
21689   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21690   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21691 }
21692 
21693 
SplitSemicolonedCallback(BioSourcePtr biop,Pointer userdata)21694 static void SplitSemicolonedCallback (BioSourcePtr biop, Pointer userdata)
21695 
21696 {
21697   CharPtr     ptr, str;
21698   OrgModPtr   nwomp, omp;
21699   OrgNamePtr  onp;
21700   OrgRefPtr   orp;
21701 
21702   orp = biop->org;
21703   if (orp == NULL) return;
21704   onp = orp->orgname;
21705   if (onp == NULL) return;
21706   for (omp = onp->mod; omp != NULL; omp = omp->next) {
21707     if (omp->subtype == ORGMOD_specimen_voucher ||
21708         omp->subtype == ORGMOD_culture_collection ||
21709         omp->subtype == ORGMOD_bio_material) {
21710       str = omp->subname;
21711       ptr = StringChr (str, ';');
21712       if (ptr == NULL) continue;
21713       *ptr = '\0';
21714       ptr++;
21715       nwomp = OrgModNew ();
21716       nwomp->subtype = omp->subtype;
21717       nwomp->subname = StringSave (ptr);
21718       nwomp->next = omp->next;
21719       omp->next = nwomp;
21720     }
21721   }
21722 }
21723 
SplitSemicolonedVouchers(IteM i)21724 static void SplitSemicolonedVouchers (IteM i)
21725 
21726 {
21727   BaseFormPtr  bfp;
21728   SeqEntryPtr  sep;
21729 
21730 #ifdef WIN_MAC
21731   bfp = currentFormDataPtr;
21732 #else
21733   bfp = GetObjectExtra (i);
21734 #endif
21735   if (bfp == NULL) return;
21736   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21737   if (sep == NULL) return;
21738 
21739   VisitBioSourcesInSep (sep, NULL, SplitSemicolonedCallback);
21740 
21741   BasicSeqEntryCleanup (sep);
21742 
21743   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21744   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21745 }
21746 
21747 
PrintDiscrepancyTestListMenuItem(IteM i)21748 static void PrintDiscrepancyTestListMenuItem (IteM i)
21749 
21750 {
21751   Char         path [PATH_MAX];
21752   FILE *fp;
21753 
21754   TmpNam (path);
21755   fp = FileOpen (path, "w");
21756   if (fp == NULL) {
21757     Message (MSG_ERROR, "Unable to open %s", path);
21758     return;
21759   }
21760   PrintDiscrepancyTestList (fp);
21761   FileClose (fp);
21762   LaunchGeneralTextViewer (path, "Discrepancy Tests List");
21763   FileRemove (path);
21764 }
21765 
21766 
ApplyKeywordWithStringConstraint(IteM i)21767 NLM_EXTERN void ApplyKeywordWithStringConstraint (IteM i)
21768 {
21769   BaseFormPtr    bfp;
21770 
21771 #ifdef WIN_MAC
21772   bfp = currentFormDataPtr;
21773 #else
21774   bfp = GetObjectExtra (i);
21775 #endif
21776   if (bfp == NULL) return;
21777 
21778   MacroApplyKeyword (bfp->input_entityID, TRUE);
21779 }
21780 
21781 
AddStructuredCommentKeywordsMenuItem(IteM i)21782 static void AddStructuredCommentKeywordsMenuItem (IteM i)
21783 {
21784   BaseFormPtr    bfp;
21785 
21786 #ifdef WIN_MAC
21787   bfp = currentFormDataPtr;
21788 #else
21789   bfp = GetObjectExtra (i);
21790 #endif
21791   if (bfp == NULL) return;
21792 
21793   AddStructuredCommentKeywords (bfp->input_entityID);
21794 }
21795 
21796 
RemoveStructuredCommentKeywordsMenuItem(IteM i)21797 static void RemoveStructuredCommentKeywordsMenuItem (IteM i)
21798 {
21799   BaseFormPtr    bfp;
21800 
21801 #ifdef WIN_MAC
21802   bfp = currentFormDataPtr;
21803 #else
21804   bfp = GetObjectExtra (i);
21805 #endif
21806   if (bfp == NULL) return;
21807 
21808   RemoveStructuredCommentKeywords (bfp->input_entityID);
21809 }
21810 
21811 
21812 
TestNewParse(IteM i)21813 static void TestNewParse (IteM i)
21814 {
21815   BaseFormPtr  bfp;
21816   ForM         f;
21817 
21818 #ifdef WIN_MAC
21819   bfp = currentFormDataPtr;
21820 #else
21821   bfp = GetObjectExtra (i);
21822 #endif
21823   if (bfp == NULL) return;
21824 
21825   f = SingleParseAction (bfp->input_entityID);
21826   if (f != NULL) {
21827     Show (f);
21828   }
21829 }
21830 
21831 
TestProductTableExport(IteM i)21832 static void TestProductTableExport (IteM i)
21833 {
21834   BaseFormPtr  bfp;
21835   Char         path[PATH_MAX];
21836   SeqEntryPtr  sep;
21837   FILE        *fp;
21838 
21839 #ifdef WIN_MAC
21840   bfp = currentFormDataPtr;
21841 #else
21842   bfp = GetObjectExtra (i);
21843 #endif
21844   if (bfp == NULL) return;
21845 
21846   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21847   if (sep == NULL) return;
21848   path [0] = '\0';
21849   if (GetOutputFileName (path, sizeof (path), NULL)) {
21850     fp = FileOpen (path, "w");
21851     if (fp == NULL) {
21852       Message (MSG_ERROR, "Unable to open %s", path);
21853     } else {
21854       ExportProductUpdateTable (sep, fp);
21855       FileClose (fp);
21856 #ifdef WIN_MSWIN
21857       Nlm_MSWin_OpenApplication ("excel.exe", path);
21858 #endif
21859     }
21860   }
21861 }
21862 
21863 
TestProductTableUpdate(IteM i)21864 static void TestProductTableUpdate (IteM i)
21865 {
21866   BaseFormPtr  bfp;
21867   Char         path[PATH_MAX];
21868   SeqEntryPtr  sep;
21869   FILE        *fp;
21870   ValNodePtr   table;
21871   LogInfoPtr   lip;
21872 
21873 #ifdef WIN_MAC
21874   bfp = currentFormDataPtr;
21875 #else
21876   bfp = GetObjectExtra (i);
21877 #endif
21878   if (bfp == NULL) return;
21879 
21880   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21881   if (sep == NULL) return;
21882   path [0] = '\0';
21883   if (GetInputFileName (path, sizeof (path), "", "TEXT")) {
21884     fp = FileOpen (path, "r");
21885     if (fp == NULL) {
21886       Message (MSG_ERROR, "Unable to open %s", path);
21887     } else {
21888       table = ReadProductUpdateTable (fp);
21889       FileClose (fp);
21890       if (table == NULL) {
21891         Message (MSG_ERROR, "Unable to read table from %s", path);
21892       } else {
21893         lip = OpenLog("Product name changes");
21894         lip->data_in_log = ApplyProductUpdateTable (table, sep, lip->fp);
21895         CloseLog (lip);
21896         FreeLog (lip);
21897         table = ProductUpdateTableFree (table);
21898         ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21899         ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21900       }
21901     }
21902   }
21903 }
21904 
21905 
WriteAccessionsCallback(BioseqPtr bsp,Pointer data)21906 static void WriteAccessionsCallback (BioseqPtr bsp, Pointer data)
21907 {
21908   Char id_txt[255];
21909   if (bsp == NULL || ISA_aa (bsp->mol) || data == NULL) {
21910     return;
21911   }
21912   SeqIdWrite (SeqIdFindBest (bsp->id, SEQID_GENBANK), id_txt, PRINTID_TEXTID_ACC_ONLY, sizeof (id_txt) - 1);
21913   fprintf ((FILE *)data, "%s\n", id_txt);
21914 }
21915 
21916 
21917 #ifdef USE_SMARTNET
21918 static CharPtr labelfungalrnascmd = NULL;
21919 #endif
21920 
LabelFungalRNAs(IteM i)21921 static void LabelFungalRNAs (IteM i)
21922 {
21923   BaseFormPtr  bfp;
21924   SeqEntryPtr  sep;
21925 #ifdef USE_SMARTNET
21926   Char         cmmd[PATH_MAX];
21927   Char         list_path[PATH_MAX];
21928 #endif
21929   Char         path[PATH_MAX];
21930   FILE        *fp = NULL;
21931   Boolean      remove_path = FALSE;
21932 
21933 #ifdef WIN_MAC
21934   bfp = currentFormDataPtr;
21935 #else
21936   bfp = GetObjectExtra (i);
21937 #endif
21938   if (bfp == NULL) return;
21939 
21940   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
21941 
21942 #ifdef USE_SMARTNET
21943   if (labelfungalrnascmd == NULL) {
21944     if (GetAppParam ("SEQUIN", "RNALABELING", "FUNGALSCRIPT", NULL, cmmd, sizeof (cmmd))) {
21945     	labelfungalrnascmd = StringSaveNoNull (cmmd);
21946     }
21947   }
21948   if (labelfungalrnascmd != NULL) {
21949     TmpNam (list_path);
21950     fp = FileOpen (list_path, "w");
21951     if (fp == NULL) {
21952       Message (MSG_ERROR, "Unable to open temporary file %s, unable to get fungal rRNA results", list_path);
21953       return;
21954     } else {
21955       /* make list of accessions to check */
21956       VisitBioseqsInSep (sep, fp, WriteAccessionsCallback);
21957       FileClose (fp);
21958       TmpNam (path);
21959       /* launch script */
21960   #ifdef OS_UNIX
21961       sprintf (cmmd, "csh %s -i \"%s\" -o \"%s\"", labelfungalrnascmd, list_path, path);
21962       system (cmmd);
21963   #endif
21964   #ifdef OS_MSWIN
21965       sprintf (cmmd, "%s -i \"%s\" -o \"%s\"", labelfungalrnascmd, list_path, path);
21966       RunSilent (cmmd);
21967   #endif
21968       FileRemove (list_path);
21969       /* read results */
21970       fp = FileOpen (path, "r");
21971       if (fp == NULL) {
21972         if (Message (MSG_OKC, "Unable to open temporary file %s for results.  Try with script results?", path) == ANS_CANCEL) {
21973           return;
21974         }
21975       } else {
21976         remove_path = TRUE;
21977       }
21978     }
21979   }
21980 #endif
21981   if (fp == NULL) {
21982     /* read from user-specified file */
21983     if (! GetInputFileName (path, sizeof (path), "", "TEXT")) return;
21984     fp = FileOpen (path, "r");
21985     if (fp == NULL) {
21986       Message (MSG_ERROR, "Unable to open %s", path);
21987       return;
21988     }
21989   }
21990 
21991   ParseExtractorResultsTableToFeatures (fp, sep);
21992   FileClose (fp);
21993   if (remove_path) {
21994     FileRemove (path);
21995   }
21996   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
21997   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
21998 }
21999 
22000 
22001 #ifdef USE_SMARTNET
22002 static CharPtr labelrnascmd = NULL;
22003 #endif
22004 
LabelNewRNAsBaseForm(BaseFormPtr bfp)22005 static void LabelNewRNAsBaseForm (BaseFormPtr  bfp)
22006 {
22007   SeqEntryPtr  sep;
22008 #ifdef USE_SMARTNET
22009   Char         cmmd[PATH_MAX];
22010   Char         list_path[PATH_MAX];
22011 #endif
22012   Char         path[PATH_MAX];
22013   FILE        *fp = NULL;
22014   Boolean      remove_path = FALSE;
22015   LogInfoPtr   lip;
22016 
22017   if (bfp == NULL) return;
22018 
22019   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
22020 
22021 #ifdef USE_SMARTNET
22022   if (labelrnascmd == NULL) {
22023     if (GetAppParam ("SEQUIN", "RNALABELING", "RNASCRIPT", NULL, cmmd, sizeof (cmmd))) {
22024     	labelrnascmd = StringSaveNoNull (cmmd);
22025     }
22026   }
22027   if (labelrnascmd != NULL) {
22028     TmpNam (list_path);
22029     fp = FileOpen (list_path, "w");
22030     if (fp == NULL) {
22031       Message (MSG_ERROR, "Unable to open temporary file %s, unable to get rRNA results", list_path);
22032       return;
22033     } else {
22034       /* make list of accessions to check */
22035       VisitBioseqsInSep (sep, fp, WriteAccessionsCallback);
22036       FileClose (fp);
22037       TmpNam (path);
22038       /* launch script */
22039   #ifdef OS_UNIX
22040       sprintf (cmmd, "csh %s -i \"%s\" -o \"%s\"", labelrnascmd, list_path, path);
22041       system (cmmd);
22042   #endif
22043   #ifdef OS_MSWIN
22044       sprintf (cmmd, "%s -i \"%s\" -o \"%s\"", labelrnascmd, list_path, path);
22045       RunSilent (cmmd);
22046   #endif
22047       FileRemove (list_path);
22048       /* read results */
22049       fp = FileOpen (path, "r");
22050       if (fp == NULL) {
22051         if (Message (MSG_OKC, "Unable to open temporary file %s for results.  Try with script results?", path) == ANS_CANCEL) {
22052           return;
22053         }
22054       } else {
22055         remove_path = TRUE;
22056       }
22057     }
22058   }
22059 #endif
22060   if (fp == NULL) {
22061     /* read from user-specified file */
22062     if (! GetInputFileName (path, sizeof (path), "", "TEXT")) return;
22063     fp = FileOpen (path, "r");
22064     if (fp == NULL) {
22065       Message (MSG_ERROR, "Unable to open %s", path);
22066       return;
22067     }
22068   }
22069 
22070   lip = OpenLog("RNA Labelling errors");
22071   ParseRNAFeatListTableToFeatures (fp, sep, lip);
22072   CloseLog(lip);
22073   lip = FreeLog (lip);
22074   FileClose (fp);
22075   if (remove_path) {
22076     FileRemove (path);
22077   }
22078   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
22079   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
22080 }
22081 
22082 
LabelNewRNAs(IteM i)22083 static void LabelNewRNAs (IteM i)
22084 {
22085   BaseFormPtr  bfp;
22086 
22087 #ifdef WIN_MAC
22088   bfp = currentFormDataPtr;
22089 #else
22090   bfp = GetObjectExtra (i);
22091 #endif
22092 
22093   LabelNewRNAsBaseForm(bfp);
22094 }
22095 
22096 
RemoveDuplicateNestedSetsMenuItem(IteM i)22097 static void RemoveDuplicateNestedSetsMenuItem (IteM i)
22098 {
22099   BaseFormPtr  bfp;
22100 
22101 #ifdef WIN_MAC
22102   bfp = currentFormDataPtr;
22103 #else
22104   bfp = GetObjectExtra (i);
22105 #endif
22106   if (bfp == NULL) return;
22107 
22108   RemoveDuplicateNestedSetsForEntityID (bfp->input_entityID);
22109 }
22110 
22111 
RunAutoFixWindowScript(BaseFormPtr bfp)22112 static void RunAutoFixWindowScript (BaseFormPtr bfp)
22113 {
22114   AsnIoPtr     aip;
22115   Char         buf [PATH_MAX];
22116   ValNodePtr   action_list;
22117 
22118   if (bfp == NULL) return;
22119 
22120   if (! FindPath("ncbi", "ncbi", "data", buf, sizeof (buf)))
22121   {
22122     Message (MSG_ERROR, "Failed to find Auto-fix script");
22123     return;
22124   }
22125 
22126   StringCat(buf, "autofix.prt");
22127 
22128   aip = AsnIoOpen (buf, "r");
22129   if (aip == NULL) {
22130     Message (MSG_ERROR, "Unable to open %s", buf);
22131     return;
22132   }
22133 
22134   action_list = MacroActionListAsnRead (aip, NULL);
22135   AsnIoClose (aip);
22136 
22137   if (action_list == NULL) {
22138     Message (MSG_ERROR, "Unable to read action list from %s.", buf);
22139     return;
22140   }
22141 
22142   SelectiveMacroRun (action_list);
22143 }
22144 
22145 
RunAutoFixScriptMenuItem(IteM i)22146 static void RunAutoFixScriptMenuItem (IteM i)
22147 {
22148   BaseFormPtr  bfp;
22149 
22150 #ifdef WIN_MAC
22151   bfp = currentFormDataPtr;
22152 #else
22153   bfp = GetObjectExtra (i);
22154 #endif
22155   if (bfp == NULL) return;
22156   RunAutoFixScript(bfp, FALSE, RefreshAllReportWindows, NULL);
22157 }
22158 
22159 
RunAutoFixWindowMenuItem(IteM i)22160 static void RunAutoFixWindowMenuItem (IteM i)
22161 {
22162   BaseFormPtr  bfp;
22163 
22164 #ifdef WIN_MAC
22165   bfp = currentFormDataPtr;
22166 #else
22167   bfp = GetObjectExtra (i);
22168 #endif
22169   if (bfp == NULL) return;
22170   RunAutoFixWindowScript(bfp);
22171 }
22172 
22173 
RunAutoFixScriptToolBtn(ButtoN b)22174 static void RunAutoFixScriptToolBtn (ButtoN b)
22175 {
22176   BaseFormPtr       bfp;
22177 
22178   bfp = (BaseFormPtr) GetObjectExtra (b);
22179   if (bfp == NULL) return;
22180   RunAutoFixScript(bfp, FALSE, RefreshAllReportWindows, NULL);
22181 }
22182 
22183 
ConvertCommentsWithSpacesToStructuredComments(IteM i)22184 static void ConvertCommentsWithSpacesToStructuredComments (IteM i)
22185 {
22186   BaseFormPtr  bfp;
22187   SeqEntryPtr  sep;
22188   Int4         n;
22189 
22190 #ifdef WIN_MAC
22191   bfp = currentFormDataPtr;
22192 #else
22193   bfp = GetObjectExtra (i);
22194 #endif
22195   if (bfp == NULL) return;
22196 
22197   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
22198   if (sep == NULL) {
22199     return;
22200   }
22201 
22202   n = ConvertCommentsWithSpacesToStructuredCommentsForSeqEntry (sep);
22203   if (n > 0) {
22204     Message (MSG_ERROR, "Unable to convert %d comments\n", n);
22205   }
22206 
22207   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
22208   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
22209   Update();
22210 }
22211 
22212 
FlipCodonRecognized(IteM i)22213 static void FlipCodonRecognized (IteM i)
22214 {
22215   BaseFormPtr  bfp;
22216   SeqEntryPtr  sep;
22217   LogInfoPtr   lip;
22218 
22219 #ifdef WIN_MAC
22220   bfp = currentFormDataPtr;
22221 #else
22222   bfp = GetObjectExtra (i);
22223 #endif
22224   if (bfp == NULL) return;
22225 
22226   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
22227   if (sep == NULL) {
22228     return;
22229   }
22230 
22231   lip = OpenLog ("codon_recognized changes");
22232   FlipCodonRecognizedInSeqEntry (sep, lip);
22233   CloseLog (lip);
22234   FreeLog (lip);
22235 
22236   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
22237   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
22238   Update();
22239 }
22240 
22241 
RemoveBadCodonRecognized(IteM i)22242 static void RemoveBadCodonRecognized (IteM i)
22243 {
22244   BaseFormPtr  bfp;
22245   SeqEntryPtr  sep;
22246   LogInfoPtr   lip;
22247 
22248 #ifdef WIN_MAC
22249   bfp = currentFormDataPtr;
22250 #else
22251   bfp = GetObjectExtra (i);
22252 #endif
22253   if (bfp == NULL) return;
22254 
22255   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
22256   if (sep == NULL) {
22257     return;
22258   }
22259 
22260   lip = OpenLog ("codon_recognized changes");
22261   RemoveBadCodonRecognizedInSeqEntry (sep, lip);
22262   CloseLog (lip);
22263   FreeLog (lip);
22264 
22265   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
22266   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
22267   Update();
22268 }
22269 
22270 
PropagateDblinkDescriptorsMenuItem(IteM i)22271 static void PropagateDblinkDescriptorsMenuItem (IteM i)
22272 {
22273   BaseFormPtr  bfp;
22274   SeqEntryPtr  sep;
22275 
22276 #ifdef WIN_MAC
22277   bfp = currentFormDataPtr;
22278 #else
22279   bfp = GetObjectExtra (i);
22280 #endif
22281   if (bfp == NULL) return;
22282 
22283   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
22284   if (sep == NULL) {
22285     return;
22286   }
22287 
22288   PropagateDblinkDescriptors (sep);
22289 
22290   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
22291   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
22292   Update();
22293 }
22294 
22295 
NewFeatureLocationEditor(IteM i)22296 static void NewFeatureLocationEditor (IteM i)
22297 {
22298   BaseFormPtr  bfp;
22299   ValNodePtr action;
22300   EditFeatureLocationActionPtr a;
22301 
22302 #ifdef WIN_MAC
22303   bfp = currentFormDataPtr;
22304 #else
22305   bfp = GetObjectExtra (i);
22306 #endif
22307   if (bfp == NULL) return;
22308 
22309   a = EditFeatureLocationActionNew ();
22310   a->action = ValNodeNew (NULL);
22311   a->action->choice = LocationEditType_extend_5;
22312   action = ValNodeNew (NULL);
22313   action->choice = MacroActionChoice_edit_location;
22314   action->data.ptrvalue = a;
22315   GenericMacroActionForm (bfp->input_entityID, action, TRUE);
22316   action = MacroActionChoiceFree(action);
22317 }
22318 
22319 
AddToBioseqSegregateList(BioseqPtr bsp,Pointer data)22320 static void AddToBioseqSegregateList (BioseqPtr bsp, Pointer data)
22321 {
22322   ValNodePtr PNTR list;
22323 
22324   if (bsp == NULL || ISA_aa (bsp->mol) || (list = (ValNodePtr PNTR) data) == NULL
22325     || ValNodeLen (*list) > 3) {
22326     return;
22327   } else {
22328     ValNodeAddPointer (list, OBJ_BIOSEQ, bsp);
22329   }
22330 }
22331 
22332 
TestSegregateByList(IteM i)22333 static void TestSegregateByList (IteM i)
22334 {
22335   BaseFormPtr  bfp;
22336   SeqEntryPtr  sep;
22337   ValNodePtr   list = NULL;
22338 
22339 #ifdef WIN_MAC
22340   bfp = currentFormDataPtr;
22341 #else
22342   bfp = GetObjectExtra (i);
22343 #endif
22344   if (bfp == NULL) return;
22345 
22346   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
22347   if (sep == NULL) {
22348     return;
22349   }
22350   VisitBioseqsInSep (sep, &list, AddToBioseqSegregateList);
22351   SegregateSetsByBioseqList (sep, list);
22352   list = ValNodeFree (list);
22353 
22354   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
22355   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
22356   Update();
22357 }
22358 
22359 
PropagateMissingOldNameQualsItem(IteM i)22360 static void PropagateMissingOldNameQualsItem (IteM i)
22361 {
22362   BaseFormPtr  bfp;
22363   SeqEntryPtr  sep;
22364   ValNodePtr   list = NULL;
22365 
22366 #ifdef WIN_MAC
22367   bfp = currentFormDataPtr;
22368 #else
22369   bfp = GetObjectExtra (i);
22370 #endif
22371   if (bfp == NULL) return;
22372 
22373   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
22374   if (sep == NULL) {
22375     return;
22376   }
22377   ValNodeAddPointer (&list, 0, sep);
22378   if (PropagateMissingOldNames (list)) {
22379     Message (MSG_OK, "Propagated old names");
22380   } else {
22381     Message (MSG_ERROR, "No old-names propagated.");
22382   }
22383   list = ValNodeFree (list);
22384 }
22385 
22386 
GetBioSampleId(BioseqPtr bsp)22387 static CharPtr GetBioSampleId (BioseqPtr bsp)
22388 {
22389   SeqDescPtr   sdp;
22390   SeqMgrDescContext context;
22391   CharPtr           id = NULL;
22392   UserObjectPtr     uop;
22393   ObjectIdPtr       oip;
22394   UserFieldPtr      ufp;
22395   CharPtr PNTR      cpp;
22396 
22397   for (sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_user, &context);
22398        sdp != NULL && id == NULL;
22399        sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_user, &context))
22400   {
22401     if ((uop = (UserObjectPtr) sdp->data.ptrvalue) != NULL
22402         && (oip = uop->type) != NULL
22403         && StringCmp (oip->str, "DBLink") == 0)
22404     {
22405       for (ufp = uop->data; ufp != NULL; ufp = ufp->next)
22406       {
22407         oip = ufp->label;
22408         if (oip == NULL) continue;
22409         if (StringICmp (oip->str, "BioSample") == 0)
22410         {
22411           if (ufp->choice == 1)
22412           {
22413             id = ufp->data.ptrvalue;
22414           }
22415           else if (ufp->choice == 7)
22416           {
22417             cpp = (CharPtr PNTR) ufp->data.ptrvalue;
22418             if (ufp->num > 0 && cpp != NULL)
22419             {
22420               id = cpp [0];
22421             }
22422           }
22423         }
22424       }
22425     }
22426   }
22427   return id;
22428 }
22429 
22430 
IsBioSampleStructuredComment(UserObjectPtr uop)22431 static Boolean IsBioSampleStructuredComment (UserObjectPtr uop)
22432 {
22433   UserFieldPtr ufp;
22434   CharPtr      str;
22435 
22436   if (uop == NULL || uop->type == NULL || StringCmp (uop->type->str, "StructuredComment") != 0) {
22437     return FALSE;
22438   }
22439   for (ufp = uop->data; ufp != NULL; ufp = ufp->next) {
22440     if (ufp->label != NULL
22441         && ufp->choice == 1
22442         && (str = (CharPtr) ufp->data.ptrvalue) != NULL
22443         && StringCmp (ufp->label->str, "StructuredCommentPrefix") == 0
22444         && StringICmp (str, "##MIMS-Data-START##") == 0) {
22445       return TRUE;
22446     }
22447   }
22448   return FALSE;
22449 }
22450 
22451 
22452 
22453 typedef struct biosamplefielddiffs {
22454   ValNodePtr src_field_list;
22455   ValNodePtr src_diff_list;
22456   ValNodePtr desc_field_list;
22457   ValNodePtr desc_diff_list;
22458   ValNodePtr biosample_ids;
22459   ValNodePtr biosample_data;
22460   ValNodePtr unretrieved_ids;
22461 } BioSampleFieldDiffsData, PNTR BioSampleFieldDiffsPtr;
22462 
22463 
BioSampleFieldDiffsFree(BioSampleFieldDiffsPtr b)22464 static BioSampleFieldDiffsPtr BioSampleFieldDiffsFree (BioSampleFieldDiffsPtr b)
22465 {
22466   ValNodePtr vnp;
22467 
22468   if (b != NULL) {
22469     b->src_field_list = FieldTypeListFree (b->src_field_list);
22470     b->desc_field_list = FieldTypeListFree (b->desc_field_list);
22471     b->src_diff_list = FieldDiffListFree(b->src_diff_list);
22472     b->desc_diff_list = FieldDiffListFree(b->desc_diff_list);
22473     b->biosample_ids = ValNodeFreeData (b->biosample_ids);
22474     for (vnp = b->biosample_data; vnp != NULL; vnp = vnp->next) {
22475       vnp->data.ptrvalue = SeqDescrFree(vnp->data.ptrvalue);
22476     }
22477     b->biosample_data = ValNodeFree (b->biosample_data);
22478     b->unretrieved_ids = ValNodeFreeData (b->unretrieved_ids);
22479     b = MemFree (b);
22480   }
22481   return b;
22482 }
22483 
22484 
GetBiosampleIds(BioseqPtr bsp,Pointer data)22485 static void GetBiosampleIds (BioseqPtr bsp, Pointer data)
22486 {
22487   CharPtr id;
22488 
22489   id = GetBioSampleId (bsp);
22490   if (!StringHasNoText (id)) {
22491     ValNodeAddPointer ((ValNodePtr PNTR) data, 0, StringSave (id));
22492   }
22493 }
22494 
22495 
SaveDescriptors(SeqDescrPtr descr)22496 static void SaveDescriptors(SeqDescrPtr descr)
22497 {
22498   AsnIoPtr aip;
22499   Char     path [PATH_MAX];
22500 
22501   TmpNam (path);
22502   aip = AsnIoOpen(path, "w");
22503   SeqDescrAsnWrite (descr, aip, NULL);
22504   AsnIoClose (aip);
22505   LaunchGeneralTextViewer (path, "BioSample Response");
22506   FileRemove(path);
22507 }
22508 
22509 
PopulateBiosampleData(BioSampleFieldDiffsPtr b)22510 static void PopulateBiosampleData (BioSampleFieldDiffsPtr b)
22511 {
22512   ValNodePtr vnp;
22513   SeqDescrPtr biosample_data;
22514   SeqDescPtr  sdp;
22515   BioSourcePtr sample_biop;
22516 
22517   for (vnp = b->biosample_ids; vnp != NULL; vnp = vnp->next) {
22518     biosample_data = SeqDescrFromBioSample (vnp->data.ptrvalue);
22519     ValNodeAddPointer (&(b->biosample_data), 0, biosample_data);
22520     if (biosample_data == NULL) {
22521       ValNodeAddPointer (&(b->unretrieved_ids), 0, StringSave (vnp->data.ptrvalue));
22522     } else {
22523       SaveDescriptors(biosample_data);
22524     }
22525 
22526     for (sdp = biosample_data; sdp != NULL; sdp = sdp->next) {
22527       if (sdp->choice == Seq_descr_source) {
22528         sample_biop = sdp->data.ptrvalue;
22529         ValNodeLink (&(b->src_field_list), GetSourceQualFieldListFromBioSource (sample_biop));
22530       } else if (sdp->choice == Seq_descr_user && IsBioSampleStructuredComment (sdp->data.ptrvalue)) {
22531         ValNodeLink (&(b->desc_field_list), GetStructuredCommentFieldListFromUserObject (sdp->data.ptrvalue));
22532       }
22533     }
22534   }
22535   b->src_field_list = ValNodeSort (b->src_field_list, SortVnpByFieldTypeAndSourceQualifier);
22536   ValNodeUnique (&(b->src_field_list), SortVnpByFieldTypeAndSourceQualifier, FieldTypeListFree);
22537   b->desc_field_list = ValNodeSort (b->desc_field_list, SortVnpByFieldTypeAndSourceQualifier);
22538   ValNodeUnique (&(b->desc_field_list), SortVnpByFieldTypeAndSourceQualifier, FieldTypeListFree);
22539 }
22540 
22541 
GetBioSampleDataFromBioSampleFieldDiffs(BioSampleFieldDiffsPtr b,CharPtr id)22542 static SeqDescrPtr GetBioSampleDataFromBioSampleFieldDiffs (BioSampleFieldDiffsPtr b, CharPtr id)
22543 {
22544   ValNodePtr v1, v2;
22545 
22546   if (b == NULL || StringHasNoText (id))
22547   {
22548     return NULL;
22549   }
22550   for (v1 = b->biosample_ids, v2 = b->biosample_data;
22551        v1 != NULL && v2 != NULL;
22552        v1 = v1->next, v2 = v2->next)
22553   {
22554     if (StringCmp (id, v1->data.ptrvalue) == 0)
22555     {
22556       return (SeqDescrPtr) v2->data.ptrvalue;
22557     }
22558   }
22559   return NULL;
22560 }
22561 
22562 
GetBiosampleUpdateFields(BioseqPtr bsp,Pointer data)22563 static void GetBiosampleUpdateFields (BioseqPtr bsp, Pointer data)
22564 {
22565   BioSampleFieldDiffsPtr b;
22566   BioSourcePtr this_biop = NULL, sample_biop = NULL;
22567   UserObjectPtr this_struc_comment = NULL, sample_struc_comment = NULL;
22568   CharPtr      id;
22569   SeqDescPtr   src_sdp, cmt_sdp, sdp;
22570   SeqDescrPtr       biosample_data;
22571   SeqMgrDescContext context;
22572   Char id_buf[PATH_MAX];
22573 
22574   if (bsp == NULL || ISA_aa (bsp->mol) || (b = (BioSampleFieldDiffsPtr) data) == NULL) {
22575     return;
22576   }
22577 
22578   src_sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &context);
22579   if (src_sdp == NULL || (this_biop = (BioSourcePtr) src_sdp->data.ptrvalue) == NULL) {
22580     return;
22581   }
22582   for (cmt_sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_user, &context);
22583        cmt_sdp != NULL && this_struc_comment == NULL;
22584        cmt_sdp = SeqMgrGetNextDescriptor (bsp, cmt_sdp, Seq_descr_user, &context)) {
22585     this_struc_comment = (UserObjectPtr) cmt_sdp->data.ptrvalue;
22586     if (!IsBioSampleStructuredComment(this_struc_comment)) {
22587       this_struc_comment = NULL;
22588     }
22589   }
22590 
22591   id = GetBioSampleId (bsp);
22592   if (StringHasNoText (id)) {
22593     return;
22594   }
22595 
22596   biosample_data = GetBioSampleDataFromBioSampleFieldDiffs (b, id);
22597 
22598   if (biosample_data == NULL) {
22599     return;
22600   }
22601   for (sdp = biosample_data; sdp != NULL; sdp = sdp->next) {
22602     if (sdp->choice == Seq_descr_source) {
22603       sample_biop = sdp->data.ptrvalue;
22604     } else if (sdp->choice == Seq_descr_user && IsBioSampleStructuredComment(sdp->data.ptrvalue)) {
22605       sample_struc_comment = sdp->data.ptrvalue;
22606     }
22607   }
22608 
22609   SeqIdWrite (SeqIdFindBest(bsp->id, SEQID_GENBANK), id_buf, PRINTID_REPORT, sizeof (id_buf) - 1);
22610   ValNodeLink (&(b->src_diff_list), GetBioSourceFieldDiffs (id_buf, id, this_biop, sample_biop, b->src_field_list, OBJ_SEQDESC, src_sdp));
22611 
22612   ValNodeLink (&(b->desc_diff_list), GetStructuredCommentFieldDiffs (id_buf, id, this_struc_comment, sample_struc_comment, b->desc_field_list, OBJ_SEQDESC, cmt_sdp));
22613 
22614 }
22615 
22616 
RemoveIdenticalMismatchesForDifferentSeqIds(ValNodePtr PNTR diff_list)22617 static void RemoveIdenticalMismatchesForDifferentSeqIds(ValNodePtr PNTR diff_list)
22618 {
22619   if (diff_list == NULL) {
22620     return;
22621   }
22622   *diff_list = ValNodeSort (*diff_list, SortVnpByFieldDiffBiosampleIdThenFieldThenVal);
22623   ValNodeUnique (diff_list, SortVnpByFieldDiffBiosampleIdThenFieldThenVal, FieldDiffListFree);
22624 }
22625 
22626 
RemoveColumnsWithNoConflicts(ValNodePtr PNTR diff_list)22627 static void RemoveColumnsWithNoConflicts(ValNodePtr PNTR diff_list)
22628 {
22629   ValNodePtr vnp, prev = NULL, vnp_x;
22630   Boolean any_diffs = FALSE;
22631   FieldDiffPtr f_prev = NULL, f_curr;
22632 
22633   if (diff_list == NULL || *diff_list == NULL) {
22634     return;
22635   }
22636 
22637   *diff_list = ValNodeSort (*diff_list, SortVnpByFieldDiffField);
22638   for (vnp = *diff_list; vnp != NULL; vnp = vnp->next) {
22639     f_curr = vnp->data.ptrvalue;
22640     if (f_prev != NULL && CompareFieldTypesEx(f_prev->field, f_curr->field, TRUE) != 0) {
22641       if (!any_diffs) {
22642         /* mark all for this column for removal */
22643         for (vnp_x = prev; vnp_x != vnp; vnp_x = vnp_x->next) {
22644           vnp_x->choice = 1;
22645         }
22646       }
22647       any_diffs = FALSE;
22648       prev = vnp;
22649       f_prev = prev->data.ptrvalue;
22650     }
22651     if (StringCmp (f_curr->val1, f_curr->val2) != 0) {
22652       any_diffs = TRUE;
22653     }
22654     if (f_prev == NULL) {
22655       prev = vnp;
22656       f_prev = vnp->data.ptrvalue;
22657     }
22658   }
22659   if (!any_diffs && prev != NULL) {
22660     /* mark all for this column for removal */
22661     for (vnp_x = prev; vnp_x != vnp; vnp_x = vnp_x->next) {
22662       vnp_x->choice = 1;
22663     }
22664   }
22665 
22666   vnp_x = ValNodeExtractList (diff_list, 1);
22667   vnp_x = FieldDiffListFree(vnp_x);
22668 }
22669 
22670 
RemapBioSampleAttributeName(CharPtr summ)22671 static CharPtr RemapBioSampleAttributeName(CharPtr summ)
22672 {
22673   if (StringCmp (summ, "country") == 0) {
22674     summ = MemFree (summ);
22675     summ = StringSave ("geo_loc_name");
22676   } else if (StringCmp (summ, "host") == 0) {
22677     summ = MemFree (summ);
22678     summ = StringSave ("specific_host");
22679   }
22680   return summ;
22681 }
22682 
22683 
PrintBioSampleUpdateHeaderFields(ValNodePtr diff_list,FILE * fp)22684 static void PrintBioSampleUpdateHeaderFields (ValNodePtr diff_list, FILE *fp)
22685 {
22686   ValNodePtr vnp;
22687   FieldDiffPtr f_prev = NULL, f_curr = NULL;
22688   CharPtr summ;
22689 
22690   for (vnp = diff_list; vnp != NULL; vnp = vnp->next) {
22691     f_curr = vnp->data.ptrvalue;
22692     if (f_prev == NULL || CompareFieldTypes(f_prev->field, f_curr->field) != 0) {
22693       summ = SummarizeFieldType(f_curr->field);
22694       summ = RemapBioSampleAttributeName(summ);
22695       fprintf (fp, "\t%s", summ);
22696       summ = MemFree (summ);
22697       f_prev = f_curr;
22698     }
22699   }
22700 }
22701 
22702 
ReportAndRemoveSequenceSampleConflictsInList(ValNodePtr PNTR diff_list,LogInfoPtr lip)22703 static void ReportAndRemoveSequenceSampleConflictsInList (ValNodePtr PNTR diff_list, LogInfoPtr lip)
22704 {
22705   ValNodePtr vnp, vnp_prev, mismatch;
22706   FieldDiffPtr f_prev = NULL, f_curr = NULL;
22707   CharPtr summ;
22708 
22709   RemoveIdenticalMismatchesForDifferentSeqIds (diff_list);
22710   *diff_list = ValNodeSort (*diff_list, SortVnpByFieldDiffField);
22711   if (*diff_list == NULL || (*diff_list)->next == NULL) {
22712     return;
22713   }
22714   vnp_prev = *diff_list;
22715   f_prev = (FieldDiffPtr) vnp_prev->data.ptrvalue;
22716   for (vnp = vnp_prev->next; vnp != NULL; vnp = vnp->next) {
22717     f_curr = vnp->data.ptrvalue;
22718     if (CompareFieldTypesEx(f_prev->field, f_curr->field, TRUE) == 0
22719         && StringCmp (f_prev->biosample_id, f_curr->biosample_id) == 0) {
22720       summ = SummarizeFieldType (f_prev->field);
22721       fprintf (lip->fp, "For Biosample %s, field %s, sequence %s has value %s, seuqence %s has value %s\n",
22722         f_prev->biosample_id, summ, f_prev->seq_id, f_prev->val1, f_curr->seq_id, f_curr->val1);
22723       summ = MemFree (summ);
22724       vnp_prev->choice = 1;
22725       vnp->choice = 1;
22726     }
22727     vnp_prev = vnp;
22728     f_prev = f_curr;
22729   }
22730   mismatch = ValNodeExtractList (diff_list, 1);
22731   mismatch = FieldDiffListFree(mismatch);
22732 }
22733 
22734 
ReportAndRemoveSequenceSampleConflicts(BioSampleFieldDiffsPtr b)22735 static void ReportAndRemoveSequenceSampleConflicts (BioSampleFieldDiffsPtr b)
22736 {
22737   LogInfoPtr lip;
22738 
22739   lip = OpenLog ("BioSource differences between sequences");
22740   ReportAndRemoveSequenceSampleConflictsInList (&(b->src_diff_list), lip);
22741   ReportAndRemoveSequenceSampleConflictsInList (&(b->desc_diff_list), lip);
22742 
22743   CloseLog (lip);
22744   lip = FreeLog (lip);
22745 }
22746 
22747 
22748 typedef enum {
22749   eConflictIgnoreAll = 0,
22750   eConflictIgnoreMissingInBioSource,
22751   eConflictIgnoreMissingInBioSample
22752 } EConflictIgnoreType;
22753 
22754 typedef struct ignoreconflict {
22755   CharPtr qual_name;
22756   EConflictIgnoreType ignore_type;
22757 } IgnoreConflictData, PNTR IgnoreConflictPtr;
22758 
22759 
22760 static IgnoreConflictData ignore_conflict_list[] = {
22761   { "rev-primer-name", eConflictIgnoreMissingInBioSample } ,
22762   { "rev-primer-seq", eConflictIgnoreMissingInBioSample } ,
22763   { "fwd-primer-name", eConflictIgnoreMissingInBioSample } ,
22764   { "fwd-primer-seq", eConflictIgnoreMissingInBioSample } ,
22765   { "environmental-sample", eConflictIgnoreMissingInBioSample } ,
22766   { "germline", eConflictIgnoreMissingInBioSample } ,
22767   { "endogenous-virus-name", eConflictIgnoreMissingInBioSample } ,
22768   { "map", eConflictIgnoreMissingInBioSample } ,
22769   { "metagenomic", eConflictIgnoreMissingInBioSample } ,
22770   { "plasmid-name", eConflictIgnoreMissingInBioSample } ,
22771   { "plastid-name", eConflictIgnoreMissingInBioSample } ,
22772   { "chromosome", eConflictIgnoreMissingInBioSample } ,
22773   { "map", eConflictIgnoreMissingInBioSample } ,
22774   { "linkage-group", eConflictIgnoreMissingInBioSample } ,
22775   { "rearranged", eConflictIgnoreMissingInBioSample } ,
22776   { "segment", eConflictIgnoreMissingInBioSample } ,
22777   { "transgenic", eConflictIgnoreMissingInBioSample } ,
22778   { "old lineage", eConflictIgnoreMissingInBioSample } ,
22779   { "old name", eConflictIgnoreMissingInBioSample } ,
22780   { "lineage", eConflictIgnoreAll } ,
22781   { "biovar", eConflictIgnoreAll } ,
22782   { "chemovar", eConflictIgnoreAll } ,
22783   { "forma", eConflictIgnoreAll } ,
22784   { "forma-specialis", eConflictIgnoreAll } ,
22785   { "pathovar", eConflictIgnoreAll } ,
22786   { "serotype", eConflictIgnoreAll } ,
22787   { "serovar", eConflictIgnoreAll } ,
22788   { "subspecies", eConflictIgnoreAll } ,
22789   { "variety", eConflictIgnoreAll } ,
22790   { NULL, eConflictIgnoreAll }};
22791 
ShouldIgnoreConflict(FieldDiffPtr diff)22792 static Boolean ShouldIgnoreConflict(FieldDiffPtr diff)
22793 {
22794   CharPtr summ;
22795   Int4 i;
22796   Boolean rval = FALSE;
22797 
22798   if (StringICmp (diff->val1, diff->val2) == 0) {
22799     return TRUE;
22800   }
22801   summ = SummarizeFieldType (diff->field);
22802   for (i = 0; ignore_conflict_list[i].qual_name != NULL; i++) {
22803     if (StringICmp (summ, ignore_conflict_list[i].qual_name) == 0) {
22804       switch (ignore_conflict_list[i].ignore_type) {
22805         case eConflictIgnoreAll:
22806           rval = TRUE;
22807           break;
22808         case eConflictIgnoreMissingInBioSource:
22809           if (StringHasNoText (diff->val1)) {
22810             rval = TRUE;
22811           }
22812           break;
22813         case eConflictIgnoreMissingInBioSample:
22814           if (StringHasNoText (diff->val2)) {
22815             rval = TRUE;
22816           }
22817           break;
22818       }
22819       break;
22820     }
22821   }
22822   summ = MemFree (summ);
22823   return rval;
22824 }
22825 
22826 
RemoveConflictsToIgnoreInList(ValNodePtr PNTR diff_list)22827 static void RemoveConflictsToIgnoreInList(ValNodePtr PNTR diff_list)
22828 {
22829   ValNodePtr vnp, ignore;
22830 
22831   if (diff_list == NULL || *diff_list == NULL) {
22832     return;
22833   }
22834   for (vnp = *diff_list; vnp != NULL; vnp = vnp->next) {
22835     if (vnp->data.ptrvalue == NULL || ShouldIgnoreConflict(vnp->data.ptrvalue)) {
22836       vnp->choice = 1;
22837     }
22838   }
22839   ignore = ValNodeExtractList (diff_list, 1);
22840   ignore = FieldDiffListFree(ignore);
22841 }
22842 
22843 
RemoveConflictsToIgnore(BioSampleFieldDiffsPtr b)22844 static void RemoveConflictsToIgnore (BioSampleFieldDiffsPtr b)
22845 {
22846   if (b == NULL) {
22847     return;
22848   }
22849   RemoveConflictsToIgnoreInList(&(b->src_diff_list));
22850   RemoveConflictsToIgnoreInList(&(b->desc_diff_list));
22851 }
22852 
22853 
GetBiosampleBioSourceDiffs(SeqEntryPtr sep)22854 static BioSampleFieldDiffsPtr GetBiosampleBioSourceDiffs (SeqEntryPtr sep)
22855 {
22856   BioSampleFieldDiffsPtr b;
22857 
22858   b = (BioSampleFieldDiffsPtr) MemNew (sizeof (BioSampleFieldDiffsData));
22859   MemSet (b, 0, sizeof (BioSampleFieldDiffsData));
22860 
22861   b->src_field_list = GetSourceQualSampleFieldList (sep);
22862   b->desc_field_list = GetStructuredCommentFieldList (sep);
22863 
22864   /* get list of existing biosample IDs */
22865   VisitBioseqsInSep (sep, &(b->biosample_ids), GetBiosampleIds);
22866   b->biosample_ids = ValNodeSort (b->biosample_ids, SortVnpByString);
22867   ValNodeUnique (&(b->biosample_ids), SortVnpByString, ValNodeFreeData);
22868 
22869   PopulateBiosampleData (b);
22870 
22871 
22872   VisitBioseqsInSep (sep, b, GetBiosampleUpdateFields);
22873 
22874   RemoveColumnsWithNoConflicts(&(b->src_diff_list));
22875   RemoveColumnsWithNoConflicts(&(b->desc_diff_list));
22876 
22877   ReportAndRemoveSequenceSampleConflicts (b);
22878   RemoveConflictsToIgnore(b);
22879 
22880   return b;
22881 }
22882 
22883 
MakeFieldCipLabel(FieldDiffPtr diff)22884 static CharPtr MakeFieldCipLabel(FieldDiffPtr diff)
22885 {
22886   CharPtr label;
22887   CharPtr field_name;
22888   CharPtr field_fmt = "%s: %s";
22889 
22890   if (diff == NULL) {
22891     return NULL;
22892   }
22893   field_name = SummarizeFieldType(diff->field);
22894   label = MemNew (sizeof (Char) * (StringLen(field_fmt) + StringLen (field_name) + StringLen (diff->val2)));
22895   sprintf (label, field_fmt, field_name, diff->val2 == NULL ? "" : diff->val2);
22896   field_name = MemFree (field_name);
22897   return label;
22898 }
22899 
22900 
ClickableListFromBioSampleFieldDiffs(BioSampleFieldDiffsPtr b)22901 static ValNodePtr ClickableListFromBioSampleFieldDiffs(BioSampleFieldDiffsPtr b)
22902 {
22903   ValNodePtr vnp;
22904   ValNodeBlock list;
22905   FieldDiffPtr diff;
22906   ClickableItemPtr biosample_cip = NULL, field_cip = NULL, val_cip = NULL;
22907   CharPtr field_name;
22908 
22909   if (b == NULL) {
22910     return NULL;
22911   }
22912 
22913   b->src_diff_list = ValNodeSort (b->src_diff_list, SortVnpByFieldDiffBiosampleIdThenFieldThenVal);
22914   b->desc_diff_list = ValNodeSort (b->desc_diff_list, SortVnpByFieldDiffBiosampleIdThenFieldThenVal);
22915 
22916   InitValNodeBlock (&list, NULL);
22917   for (vnp = b->src_diff_list; vnp != NULL; vnp = vnp->next) {
22918     diff = (FieldDiffPtr) vnp->data.ptrvalue;
22919     if (diff != NULL) {
22920       if (biosample_cip == NULL || StringCmp (biosample_cip->description, diff->biosample_id) != 0) {
22921         biosample_cip = MemNew (sizeof (ClickableItemData));
22922         MemSet (biosample_cip, 0, sizeof(ClickableItemData));
22923         biosample_cip->description = StringSave (diff->biosample_id);
22924         ValNodeAddPointerToEnd (&list, 0, biosample_cip);
22925         field_cip = NULL;
22926         val_cip = NULL;
22927       }
22928       field_name = MakeFieldCipLabel(diff);
22929       if (field_cip == NULL || StringCmp (field_cip->description, field_name) != 0) {
22930         if (field_cip != NULL) {
22931           /* TODO: change field_cip description to indicate whether all fields below are the same */
22932         }
22933         field_cip = MemNew (sizeof (ClickableItemData));
22934         MemSet (field_cip, 0, sizeof(ClickableItemData));
22935         field_cip->description = StringSave(field_name);
22936         ValNodeAddPointer (&(biosample_cip->subcategories), 0, field_cip);
22937         val_cip = NULL;
22938       }
22939       field_name = MemFree (field_name);
22940       if (val_cip == NULL || StringCmp (diff->val1, val_cip->description)) {
22941         val_cip = MemNew (sizeof (ClickableItemData));
22942         MemSet (val_cip, 0, sizeof(ClickableItemData));
22943         val_cip->description = StringSave (diff->val1);
22944         ValNodeAddPointer (&(field_cip->subcategories), 0, val_cip);
22945       }
22946       ValNodeAddPointer (&(val_cip->item_list), diff->src->choice, diff->src->data.ptrvalue);
22947     }
22948   }
22949   ExpandClickableItemList(list.head);
22950   return list.head;
22951 }
22952 
22953 
ListUnresolvedBioSampleIds(ValNodePtr list)22954 static void ListUnresolvedBioSampleIds (ValNodePtr list)
22955 {
22956   LogInfoPtr   lip;
22957   ValNodePtr   vnp;
22958 
22959   if (list == NULL) {
22960     return;
22961   }
22962   lip = OpenLog ("Unresolved Biosample IDs");
22963   lip->data_in_log = TRUE;
22964   for (vnp = list; vnp != NULL; vnp = vnp->next) {
22965     fprintf (lip->fp, "%s\n", (CharPtr) vnp->data.ptrvalue);
22966   }
22967   CloseLog(lip);
22968   FreeLog(lip);
22969 }
22970 
22971 
MakeBioSampleUpdateTable(IteM i)22972 static void MakeBioSampleUpdateTable (IteM i)
22973 {
22974   BaseFormPtr  bfp;
22975   SeqEntryPtr  sep;
22976   BioSampleFieldDiffsPtr b;
22977   FILE *fp;
22978   Char path[PATH_MAX];
22979   ValNodePtr vnp_s, vnp_d;
22980   FieldDiffPtr sdiff, ddiff, diff;
22981   CharPtr prev_biosample_id;
22982 
22983 #ifdef WIN_MAC
22984   bfp = currentFormDataPtr;
22985 #else
22986   bfp = GetObjectExtra (i);
22987 #endif
22988   if (bfp == NULL) return;
22989 
22990   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
22991   if (sep == NULL) {
22992     return;
22993   }
22994   WatchCursor();
22995   Update();
22996   b = GetBiosampleBioSourceDiffs(sep);
22997 
22998   ArrowCursor();
22999   Update();
23000 
23001   ListUnresolvedBioSampleIds(b->unretrieved_ids);
23002 
23003   if (b->src_diff_list == NULL && b->desc_diff_list == NULL) {
23004     Message (MSG_OK, "No differences found for resolved Biosample IDs!");
23005     b = BioSampleFieldDiffsFree(b);
23006     return;
23007   }
23008   if (!GetOutputFileName (path, sizeof (path), NULL)) {
23009     b = BioSampleFieldDiffsFree(b);
23010     return;
23011   }
23012   fp = FileOpen (path, "w");
23013   if (fp == NULL) {
23014     Message (MSG_ERROR, "Unable to open %s", path);
23015     b = BioSampleFieldDiffsFree(b);
23016     return;
23017   }
23018 
23019   /* print header */
23020   fprintf (fp, "source_id");
23021   b->src_diff_list = ValNodeSort (b->src_diff_list, SortVnpByFieldDiffField);
23022   PrintBioSampleUpdateHeaderFields(b->src_diff_list, fp);
23023   b->desc_diff_list = ValNodeSort (b->desc_diff_list, SortVnpByFieldDiffField);
23024   PrintBioSampleUpdateHeaderFields(b->desc_diff_list, fp);
23025   fprintf (fp, "\n");
23026 
23027   /* print table lines */
23028   b->src_diff_list = ValNodeSort (b->src_diff_list, SortVnpByFieldDiffBiosampleIdThenFieldThenVal);
23029   b->desc_diff_list = ValNodeSort (b->desc_diff_list, SortVnpByFieldDiffBiosampleIdThenFieldThenVal);
23030   vnp_s = b->src_diff_list;
23031   vnp_d = b->desc_diff_list;
23032   prev_biosample_id = NULL;
23033   while (vnp_s != NULL || vnp_d != NULL) {
23034     if (vnp_s == NULL) {
23035       sdiff = NULL;
23036     } else {
23037       sdiff = vnp_s->data.ptrvalue;
23038     }
23039     if (vnp_d == NULL) {
23040       ddiff = NULL;
23041     } else {
23042       ddiff = vnp_d->data.ptrvalue;
23043     }
23044     if (sdiff == NULL && ddiff == NULL) {
23045       /* done */
23046     } else if (sdiff == NULL) {
23047       diff = ddiff;
23048     } else if (ddiff == NULL) {
23049       diff = sdiff;
23050     } else if (StringCmp (ddiff->biosample_id, sdiff->biosample_id) < 0) {
23051       diff = ddiff;
23052     } else {
23053       diff = sdiff;
23054     }
23055 
23056     if (prev_biosample_id == NULL
23057         || StringCmp (prev_biosample_id, diff->biosample_id) != 0) {
23058       if (prev_biosample_id != NULL) {
23059         fprintf (fp, "\n");
23060       }
23061       fprintf (fp, "%s", diff->biosample_id);
23062       prev_biosample_id = diff->biosample_id;
23063     }
23064     fprintf (fp, "\t%s", diff->val1);
23065     if (diff == ddiff) {
23066       vnp_d = vnp_d->next;
23067     } else if (diff == sdiff) {
23068       vnp_s = vnp_s->next;
23069     }
23070   }
23071 
23072   FileClose (fp);
23073   b = BioSampleFieldDiffsFree(b);
23074 }
23075 
23076 
FindFirstEntry(SeqEntryPtr sep)23077 static SeqEntryPtr FindFirstEntry (SeqEntryPtr sep)
23078 {
23079   BioseqSetPtr bssp;
23080 
23081   if (sep == NULL) {
23082     return NULL;
23083   } else if (IS_Bioseq(sep)) {
23084     return sep;
23085   } else if (IS_Bioseq_set(sep) && (bssp = (BioseqSetPtr) sep->data.ptrvalue) != NULL) {
23086     if (bssp->_class == BioseqseqSet_class_nuc_prot) {
23087       return sep;
23088     } else {
23089       return FindFirstEntry(bssp->seq_set);
23090     }
23091   } else {
23092     return NULL;
23093   }
23094 }
23095 
23096 
CompareWithBioSampleEx(IteM i,Boolean just_first)23097 static void CompareWithBioSampleEx (IteM i, Boolean just_first)
23098 {
23099   BaseFormPtr  bfp;
23100   SeqEntryPtr  sep;
23101   LogInfoPtr   lip;
23102   BioSampleFieldDiffsPtr b;
23103   ValNodePtr vnp_s, vnp_d;
23104   FieldDiffPtr sdiff, ddiff, diff;
23105   CharPtr prev_biosample_id;
23106   CharPtr summ;
23107 
23108 #ifdef WIN_MAC
23109   bfp = currentFormDataPtr;
23110 #else
23111   bfp = GetObjectExtra (i);
23112 #endif
23113   if (bfp == NULL) return;
23114 
23115   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
23116   if (just_first) {
23117     sep = FindFirstEntry(sep);
23118   }
23119 
23120   if (sep == NULL) {
23121     return;
23122   }
23123 
23124   WatchCursor();
23125   Update();
23126 
23127   b = GetBiosampleBioSourceDiffs(sep);
23128 
23129   ArrowCursor();
23130   Update();
23131 
23132   ListUnresolvedBioSampleIds(b->unretrieved_ids);
23133 
23134   if (b->src_diff_list == NULL && b->desc_diff_list == NULL) {
23135     Message (MSG_OK, "No differences found for resolved Biosample IDs!");
23136     b = BioSampleFieldDiffsFree(b);
23137     return;
23138   }
23139 
23140   ShowClickableItemList(ClickableListFromBioSampleFieldDiffs(b), bfp, "BioSample Conflicts", "Values", "Objects");
23141 
23142   lip = OpenLog ("Biosample Conflicts");
23143   lip->data_in_log = TRUE;
23144 
23145   /* print table lines */
23146   b->src_diff_list = ValNodeSort (b->src_diff_list, SortVnpByFieldDiffBiosampleIdThenFieldThenVal);
23147   b->desc_diff_list = ValNodeSort (b->desc_diff_list, SortVnpByFieldDiffBiosampleIdThenFieldThenVal);
23148   vnp_s = b->src_diff_list;
23149   vnp_d = b->desc_diff_list;
23150   prev_biosample_id = NULL;
23151   while (vnp_s != NULL || vnp_d != NULL) {
23152     if (vnp_s == NULL) {
23153       sdiff = NULL;
23154     } else {
23155       sdiff = vnp_s->data.ptrvalue;
23156     }
23157     if (vnp_d == NULL) {
23158       ddiff = NULL;
23159     } else {
23160       ddiff = vnp_d->data.ptrvalue;
23161     }
23162     if (sdiff == NULL && ddiff == NULL) {
23163       /* done */
23164     } else if (sdiff == NULL) {
23165       diff = ddiff;
23166     } else if (ddiff == NULL) {
23167       diff = sdiff;
23168     } else if (StringCmp (ddiff->biosample_id, sdiff->biosample_id) < 0) {
23169       diff = ddiff;
23170     } else {
23171       diff = sdiff;
23172     }
23173 
23174     if (prev_biosample_id == NULL
23175         || StringCmp (prev_biosample_id, diff->biosample_id) != 0) {
23176       if (prev_biosample_id != NULL) {
23177         fprintf (lip->fp, "\n");
23178       }
23179       fprintf (lip->fp, "%s\n", diff->biosample_id);
23180       prev_biosample_id = diff->biosample_id;
23181     }
23182     summ = SummarizeFieldType(diff->field);
23183     summ = RemapBioSampleAttributeName(summ);
23184     fprintf (lip->fp, "%s: BioSource:%s Biosample: %s\n", summ, diff->val1, diff->val2);
23185     summ = MemFree (summ);
23186     if (diff == ddiff) {
23187       vnp_d = vnp_d->next;
23188     } else if (diff == sdiff) {
23189       vnp_s = vnp_s->next;
23190     }
23191   }
23192 
23193   CloseLog (lip);
23194   lip = FreeLog (lip);
23195 
23196   b = BioSampleFieldDiffsFree(b);
23197 }
23198 
23199 
CompareWithBioSample(IteM i)23200 static void CompareWithBioSample (IteM i)
23201 {
23202   CompareWithBioSampleEx(i, FALSE);
23203 }
23204 
23205 
CompareWithBioSampleOnlyFirst(IteM i)23206 static void CompareWithBioSampleOnlyFirst (IteM i)
23207 {
23208   CompareWithBioSampleEx(i, TRUE);
23209 }
23210 
23211 
AddMissingFieldsFromBioSampleCallback(BioseqPtr bsp,Pointer data)23212 static void AddMissingFieldsFromBioSampleCallback (BioseqPtr bsp, Pointer data)
23213 {
23214   BioSampleFieldDiffsPtr b;
23215   ValNodePtr vnp;
23216   FieldDiffPtr diff;
23217   SeqDescPtr sdp;
23218   SeqMgrDescContext context;
23219   UserObjectPtr this_struc_comment = NULL;
23220   BioSourcePtr this_biop = NULL;
23221   CharPtr id;
23222 
23223   if (bsp == NULL || ISA_aa (bsp->mol) || (b = (BioSampleFieldDiffsPtr) data) == NULL) {
23224     return;
23225   }
23226 
23227   sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &context);
23228   if (sdp == NULL || (this_biop = (BioSourcePtr) sdp->data.ptrvalue) == NULL) {
23229     return;
23230   }
23231   for (sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_user, &context);
23232        sdp != NULL && this_struc_comment == NULL;
23233        sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_user, &context)) {
23234     this_struc_comment = (UserObjectPtr) sdp->data.ptrvalue;
23235     if (!IsBioSampleStructuredComment(this_struc_comment)) {
23236       this_struc_comment = NULL;
23237     }
23238   }
23239 
23240   id = GetBioSampleId (bsp);
23241   if (StringHasNoText (id)) {
23242     return;
23243   }
23244 
23245   for (vnp = b->src_diff_list; vnp != NULL; vnp = vnp->next) {
23246     diff = (FieldDiffPtr) vnp->data.ptrvalue;
23247     if (diff != NULL && StringCmp (diff->biosample_id, id) == 0
23248         && !StringHasNoText (diff->val2)) {
23249       SetSourceQualInBioSource (this_biop, diff->field->data.ptrvalue, NULL, diff->val2, ExistingTextOption_replace_old);
23250     }
23251   }
23252 
23253   /* TODO: structured comment updates? */
23254 }
23255 
23256 
23257 typedef struct updatefrombiosampledlgdata {
23258   FORM_MESSAGE_BLOCK
23259   ButtoN PNTR btns;
23260   Int4 num_btns;
23261   BioSampleFieldDiffsPtr b;
23262 } UpdateFromBiosampleDlgData, PNTR UpdateFromBiosampleDlgPtr;
23263 
23264 
CleanupUpdateFromBiosampleDlg(GraphiC g,VoidPtr data)23265 static void CleanupUpdateFromBiosampleDlg (GraphiC g, VoidPtr data)
23266 {
23267   UpdateFromBiosampleDlgPtr dlg;
23268 
23269   dlg = (UpdateFromBiosampleDlgPtr) data;
23270   if (dlg != NULL)
23271   {
23272     dlg->b = BioSampleFieldDiffsFree(dlg->b);
23273     dlg->btns = MemFree (dlg->btns);
23274   }
23275   StdCleanupFormProc (g, data);
23276 }
23277 
23278 
SummarizeFieldDiff(FieldDiffPtr diff)23279 static CharPtr SummarizeFieldDiff (FieldDiffPtr diff)
23280 {
23281   CharPtr summ = NULL, field;
23282   CharPtr fmt = "%s: BioSource:%s Biosample: %s";
23283 
23284   if (diff == NULL) {
23285     return NULL;
23286   }
23287   field = SummarizeFieldType(diff->field);
23288   field = RemapBioSampleAttributeName(field);
23289   summ = (CharPtr) MemNew (sizeof (Char) * (StringLen (fmt) + StringLen (field) + StringLen (diff->val1) + StringLen (diff->val2)));
23290   sprintf (summ, fmt, field, diff->val1 == NULL ? "" : diff->val1, diff->val2 == NULL ? "" : diff->val2);
23291   field = MemFree (field);
23292   return summ;
23293 }
23294 
23295 
DoAddMissingFieldsFromBioSample(ButtoN b)23296 static void DoAddMissingFieldsFromBioSample (ButtoN b)
23297 {
23298   UpdateFromBiosampleDlgPtr dlg;
23299   SeqEntryPtr sep;
23300   ValNodePtr vnp, prev = NULL, next;
23301   Int4       j;
23302 
23303   dlg = (UpdateFromBiosampleDlgPtr) GetObjectExtra (b);
23304   if (dlg == NULL) {
23305     return;
23306   }
23307 
23308   /* remove unchecked items from list */
23309   j = 0;
23310   for (vnp = dlg->b->src_diff_list; vnp != NULL; vnp = next) {
23311     next = vnp->next;
23312     if (!GetStatus (dlg->btns[j])) {
23313       if (prev == NULL) {
23314         dlg->b->src_diff_list = next;
23315       } else {
23316         prev->next = next;
23317       }
23318       vnp->next = NULL;
23319       vnp = FieldDiffListFree(vnp);
23320     } else {
23321       prev = vnp;
23322     }
23323     j++;
23324   }
23325   prev = NULL;
23326   for (vnp = dlg->b->desc_diff_list; vnp != NULL; vnp = next) {
23327     next = vnp->next;
23328     if (!GetStatus (dlg->btns[j])) {
23329       if (prev == NULL) {
23330         dlg->b->desc_diff_list = next;
23331       } else {
23332         prev->next = next;
23333       }
23334       vnp->next = NULL;
23335       vnp = FieldDiffListFree(vnp);
23336     } else {
23337       prev = vnp;
23338     }
23339     j++;
23340   }
23341 
23342   sep = GetTopSeqEntryForEntityID (dlg->input_entityID);
23343   VisitBioseqsInSep (sep, dlg->b, AddMissingFieldsFromBioSampleCallback);
23344   ObjMgrSetDirtyFlag (dlg->input_entityID, TRUE);
23345   ObjMgrSendMsg (OM_MSG_UPDATE, dlg->input_entityID, 0, 0);
23346 
23347   Remove (dlg->form);
23348 }
23349 
23350 
SelectAllBioSampleFields(ButtoN b)23351 static void SelectAllBioSampleFields(ButtoN b)
23352 {
23353   UpdateFromBiosampleDlgPtr dlg;
23354   Int4       j;
23355 
23356   dlg = (UpdateFromBiosampleDlgPtr) GetObjectExtra (b);
23357   if (dlg == NULL) {
23358     return;
23359   }
23360 
23361   j = 0;
23362   for (j = 0; j < dlg->num_btns; j++) {
23363     SetStatus (dlg->btns[j], TRUE);
23364   }
23365 }
23366 
23367 
AddMissingFieldsFromBioSample(IteM i)23368 static void AddMissingFieldsFromBioSample (IteM i)
23369 {
23370   BaseFormPtr  bfp;
23371   SeqEntryPtr  sep;
23372   BioSampleFieldDiffsPtr b;
23373   FieldDiffPtr diff;
23374   UpdateFromBiosampleDlgPtr dlg;
23375   WindoW w;
23376   GrouP  h, g, c;
23377   Int4   j;
23378   ValNodePtr vnp;
23379   CharPtr    summ, prev = NULL;
23380   ButtoN btn, all_btn;
23381 
23382 #ifdef WIN_MAC
23383   bfp = currentFormDataPtr;
23384 #else
23385   bfp = GetObjectExtra (i);
23386 #endif
23387   if (bfp == NULL) return;
23388 
23389   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
23390   if (sep == NULL) {
23391     return;
23392   }
23393 
23394   WatchCursor();
23395   Update();
23396   b = GetBiosampleBioSourceDiffs(sep);
23397 
23398   ArrowCursor();
23399   Update();
23400 
23401   ListUnresolvedBioSampleIds(b->unretrieved_ids);
23402 
23403   if (b->src_diff_list == NULL && b->desc_diff_list == NULL) {
23404     Message (MSG_OK, "No differences found for resolved Biosample IDs!");
23405     b = BioSampleFieldDiffsFree(b);
23406     return;
23407   }
23408 
23409   w = FixedWindow (-50, -33, -10, -10, "Select Biosample Differences to Apply", StdCloseWindowProc);
23410   if (w == NULL)
23411   {
23412     b = BioSampleFieldDiffsFree(b);
23413 	  return;
23414   }
23415   dlg = (UpdateFromBiosampleDlgPtr) MemNew (sizeof (UpdateFromBiosampleDlgData));
23416   dlg->form = (ForM) w;
23417   SetObjectExtra (w, dlg, CleanupUpdateFromBiosampleDlg);
23418   dlg->input_entityID = bfp->input_entityID;
23419   dlg->b = b;
23420 
23421   h = HiddenGroup (w, -1, 0, NULL);
23422 
23423   g = NormalGroup (h, 5, 0, "Apply Biosample Values to BioSource", programFont, NULL);
23424   SetGroupSpacing (g, 40, 10);
23425   StaticPrompt (g, "Biosample ID", 0, dialogTextHeight, programFont, 'l');
23426   StaticPrompt (g, "Apply", 0, dialogTextHeight, programFont, 'l');
23427   StaticPrompt (g, "Field", 0, dialogTextHeight, programFont, 'l');
23428   StaticPrompt (g, "Biosource Value", 0, dialogTextHeight, programFont, 'l');
23429   StaticPrompt (g, "Biosample Value", 0, dialogTextHeight, programFont, 'l');
23430 
23431   dlg->num_btns = ValNodeLen (dlg->b->src_diff_list) + ValNodeLen (dlg->b->desc_diff_list);
23432   dlg->btns = (ButtoN PNTR) MemNew (sizeof (ButtoN) * dlg->num_btns);
23433   j = 0;
23434   vnp = dlg->b->src_diff_list;
23435   while (vnp != NULL) {
23436     diff = (FieldDiffPtr) vnp->data.ptrvalue;
23437     /* biosample ID */
23438     if (StringCmp (prev, diff->biosample_id) != 0) {
23439       StaticPrompt (g, diff->biosample_id, 0, dialogTextHeight, programFont, 'l');
23440       prev = diff->biosample_id;
23441     } else {
23442       StaticPrompt (g, "", 0, dialogTextHeight, programFont, 'l');
23443     }
23444 
23445     /* checkbox */
23446     dlg->btns[j++] = CheckBox (g, "", NULL);
23447     /* field */
23448     summ = SummarizeFieldType (diff->field);
23449     StaticPrompt (g, summ, 0, dialogTextHeight, programFont, 'l');
23450     summ = MemFree (summ);
23451     /* biosource value */
23452     StaticPrompt (g, diff->val1, 0, dialogTextHeight, programFont, 'l');
23453     /* biosample value */
23454     StaticPrompt (g, diff->val2, 0, dialogTextHeight, programFont, 'l');
23455     vnp = vnp->next;
23456   }
23457   vnp = dlg->b->desc_diff_list;
23458   while (vnp != NULL) {
23459     dlg->btns[j++] = CheckBox (g, summ, NULL);
23460     diff = (FieldDiffPtr) vnp->data.ptrvalue;
23461     /* biosample ID */
23462     StaticPrompt (g, diff->biosample_id, 0, dialogTextHeight, programFont, 'l');
23463     /* field */
23464     summ = SummarizeFieldType (diff->field);
23465     StaticPrompt (g, summ, 0, dialogTextHeight, programFont, 'l');
23466     summ = MemFree (summ);
23467     /* biosource value */
23468     StaticPrompt (g, diff->val1, 0, dialogTextHeight, programFont, 'l');
23469     /* biosample value */
23470     StaticPrompt (g, diff->val2, 0, dialogTextHeight, programFont, 'l');
23471     vnp = vnp->next;
23472   }
23473 
23474   all_btn = PushButton (h, "Select All", SelectAllBioSampleFields);
23475   SetObjectExtra (all_btn, dlg, NULL);
23476 
23477   c = HiddenGroup (h, 4, 0, NULL);
23478   btn = DefaultButton (c, "Accept", DoAddMissingFieldsFromBioSample);
23479   SetObjectExtra (btn, dlg, NULL);
23480   btn = PushButton (c, "Cancel", StdCancelButtonProc);
23481   SetObjectExtra (btn, dlg, NULL);
23482   AlignObjects (ALIGN_CENTER,
23483                 (HANDLE) g,
23484                 (HANDLE) all_btn,
23485                 (HANDLE) c,
23486                 NULL);
23487 
23488   RealizeWindow (w);
23489   Show (w);
23490   Update ();
23491 }
23492 
23493 
ConvertBadToMiscFeat(IteM i)23494 static void ConvertBadToMiscFeat (IteM i)
23495 {
23496   BaseFormPtr  bfp;
23497   SeqEntryPtr  sep;
23498   LogInfoPtr lip;
23499 
23500 #ifdef WIN_MAC
23501   bfp = currentFormDataPtr;
23502 #else
23503   bfp = GetObjectExtra (i);
23504 #endif
23505   if (bfp == NULL) return;
23506 
23507   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
23508   if (sep == NULL) {
23509     return;
23510   }
23511   lip = OpenLog("Feature Conversions");
23512   ConvertFailedCodingRegionsAndRNAsToMiscFeatures(sep, lip);
23513   CloseLog (lip);
23514   lip = FreeLog(lip);
23515   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
23516   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
23517 }
23518 
23519 
GlobalDisableStrainForwardingCallback(BioSourcePtr biop,Pointer userdata)23520 static void GlobalDisableStrainForwardingCallback(BioSourcePtr biop, Pointer userdata)
23521 {
23522   DisableStrainForwarding(biop, TRUE);
23523 }
23524 
23525 
GlobalDisableStrainForwarding(IteM i)23526 static void GlobalDisableStrainForwarding (IteM i)
23527 {
23528   BaseFormPtr  bfp;
23529   SeqEntryPtr  sep;
23530   LogInfoPtr lip;
23531 
23532 #ifdef WIN_MAC
23533   bfp = currentFormDataPtr;
23534 #else
23535   bfp = GetObjectExtra (i);
23536 #endif
23537   if (bfp == NULL) return;
23538 
23539   sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
23540   if (sep == NULL) {
23541     return;
23542   }
23543   VisitBioSourcesInSep (sep, NULL, GlobalDisableStrainForwardingCallback);
23544 
23545   ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
23546   ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
23547 }
23548 
RefreshDefLineCallback(BioseqPtr bsp,Pointer data)23549 static void RefreshDefLineCallback(BioseqPtr bsp, Pointer data)
23550 {
23551     RegenerateAutoDef(bsp);
23552 }
23553 
RefreshDefLine(IteM i)23554 static void RefreshDefLine(IteM i)
23555 {
23556     BaseFormPtr  bfp;
23557     SeqEntryPtr  sep;
23558 
23559 #ifdef WIN_MAC
23560     bfp = currentFormDataPtr;
23561 #else
23562     bfp = GetObjectExtra(i);
23563 #endif
23564     if (bfp == NULL) return;
23565 
23566     sep = GetTopSeqEntryForEntityID(bfp->input_entityID);
23567     if (sep == NULL) {
23568         return;
23569     }
23570     VisitBioseqsInSep(sep, NULL, RefreshDefLineCallback);
23571 
23572     ObjMgrSetDirtyFlag(bfp->input_entityID, TRUE);
23573     ObjMgrSendMsg(OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
23574 }
23575 
MakeSpecialOrganismMenu(MenU m,BaseFormPtr bfp)23576 static void MakeSpecialOrganismMenu (MenU m, BaseFormPtr bfp)
23577 {
23578   IteM  i;
23579   MenU  s;
23580   MenU  x;
23581 
23582   s = SubMenu (m, "Organism/ G");
23583   i = CommandItem (s, "Parse Text After Bionomial", ParseTaxnameToSourceQual);
23584   SetObjectExtra (i, bfp, NULL);
23585   SeparatorItem (s);
23586   i = CommandItem (s, "Parse ATCC to Culture Collection", AtccToCultureCollection);
23587   SetObjectExtra (i, bfp, NULL);
23588   SeparatorItem (s);
23589   i = CommandItem (s, "Trim Organism Name", TrimOrganismName);
23590   SetObjectExtra (i, bfp, NULL);
23591   i = CommandItem (s, "Genus-Species Fixup", GenSpecTaxonFixup);
23592   SetObjectExtra (i, bfp, NULL);
23593   SeparatorItem (s);
23594   i = CommandItem (s, "Prefix Authority with Organism", PrefixAuthorityWithOrganism);
23595   SetObjectExtra (i, bfp, NULL);
23596   i = CommandItem (s, "Append Modifier to Organism", AddModToOrg);
23597   SetObjectExtra (i, bfp, NULL);
23598   i = CommandItem (s, "Parse Trinomial into Subspecies", ParseTrinomial);
23599   SetObjectExtra (i, bfp, NULL);
23600   SeparatorItem (s);
23601   x = SubMenu (s, "Country Fixup");
23602   i = CommandItem (x, "Do Not Fix Capitalization After Colon", CountryLookupWithoutCapFix);
23603   SetObjectExtra (i, bfp, NULL);
23604   i = CommandItem (x, "Fix Capitalization After Colon", CountryLookupWithCapFix);
23605   SetObjectExtra (i, bfp, NULL);
23606   i = CommandItem (s, "Lat-lon Tool", LatLonTool);
23607   SetObjectExtra (i, bfp, NULL);
23608   i = CommandItem (s, "Lat-Lon Country Conflict Tool", LatLonCountryTool);
23609   SetObjectExtra (i, bfp, NULL);
23610   i = CommandItem (s, "Fix Specific-Host Values", FixSpecificHostValues);
23611   SetObjectExtra (i, bfp, NULL);
23612 
23613   i = CommandItem (s, "Make Bad Specific-Host Table", MakeBadSpecificHostValueTable);
23614   SetObjectExtra (i, bfp, NULL);
23615   i = CommandItem (s, "List Failed Taxonomy Lookups", ListFailedTaxonomyLookups);
23616   SetObjectExtra (i, bfp, NULL);
23617   i = CommandItem (s, "Uncultured TaxFix Tool", TaxFixTool);
23618   SetObjectExtra (i, bfp, NULL);
23619   SeparatorItem (s);
23620   i = CommandItem (s, "Abbreviate Voucher Institution Codes", UpdateVoucherName);
23621   SetObjectExtra (i, bfp, NULL);
23622   i = CommandItem (s, "Remove Incorrect Collection Code", RemoveBadCollectionCode);
23623   SetObjectExtra (i, bfp, NULL);
23624   i = CommandItem (s, "Remove Incorrect Institution Country", RemoveBadCountry);
23625   SetObjectExtra (i, bfp, NULL);
23626   SeparatorItem (s);
23627 
23628   x = SubMenu (s, "Parse CollectionDate formats");
23629   i = CommandItem (x, "Month First", ParseCollectionDateMonthFirst);
23630   SetObjectExtra (i, bfp, NULL);
23631   i = CommandItem (x, "Day First", ParseCollectionDateDayFirst);
23632   SetObjectExtra (i, bfp, NULL);
23633     SeparatorItem (s);
23634   x = SubMenu (s, "Source Focus");
23635   i = CommandItem (x, "Set", SetSourceFocus);
23636   SetObjectExtra (i, bfp, NULL);
23637   i = CommandItem (x, "Clear", ClearSourceFocus);
23638   SetObjectExtra (i, bfp, NULL);
23639   SeparatorItem (s);
23640   i = CommandItem (s, "Set Transgenic on Source Desc when Source Feat Present", SetTransgenicOnSourceDescWhenSourceFeatPresent);
23641   SetObjectExtra (i, bfp, NULL);
23642   SeparatorItem (s);
23643 
23644   x = SubMenu (s, "Consolidate Like Modifiers");
23645   i = CommandItem (x, "With semicolons", ConsolidateLikeModifiersWithSemicolons);
23646   SetObjectExtra (i, bfp, NULL);
23647   i = CommandItem (x, "Without semicolons", ConsolidateLikeModifiersWithoutSemicolons);
23648   SetObjectExtra (i, bfp, NULL);
23649   SeparatorItem (s);
23650   x = SubMenu(s, "Parse Organism Modifiers");
23651   i = CommandItem (x, "Load From File", LoadOrganismModifierTable);
23652   SetObjectExtra (i, bfp, NULL);
23653   i = CommandItem (x, "Load Tax Consult File", LoadTaxConsult);
23654   SetObjectExtra (i, bfp, NULL);
23655 /*  i = CommandItem (x, "New Source Table Reader", NewLoadSourceQualifierTable);
23656   SetObjectExtra (i, bfp, NULL); */
23657 /*
23658   i = CommandItem (x, "Export To File", ExportOrganismTable);
23659 */
23660   i = CommandItem (x, "Export to File", ExportQualifiers);
23661   SetObjectExtra (i, bfp, NULL);
23662   i = CommandItem (x, "Export Last Lineage Table", ExportLastLineage);
23663   SetObjectExtra (i, bfp, NULL);
23664   i = CommandItem (x, "Load Tax Table", LoadTaxTableReader);
23665   SetObjectExtra (i, bfp, NULL);
23666   i = CommandItem (s, "Parse File to Source", ParseFileToSource);
23667   SetObjectExtra (i, bfp, NULL);
23668   SeparatorItem (s);
23669   x = SubMenu (s, "Add Type Strain Comments");
23670   i = CommandItem (x, "To All", AddTypeStrainCommentsToAll);
23671   SetObjectExtra (i, bfp, NULL);
23672   i = CommandItem (x, "With Constraints", AddTypeStrainCommentsWithConstraint);
23673   SetObjectExtra (i, bfp, NULL);
23674   SeparatorItem (s);
23675   x = SubMenu (s, "Influenza Virus Names");
23676   i = CommandItem (x, "Parse Strain,Serotype from Names",
23677                    ParseInfluenzaAVirusNames);
23678   SetObjectExtra (i, bfp, NULL);
23679   i = CommandItem (x, "Add Strain,Serotype to Names",
23680                    AddStrainAndSerotypeToInfluenzaAVirusNames);
23681   SetObjectExtra (i, bfp, NULL);
23682   i = CommandItem (x, "Fixup Organism Names", FixupInfluenzaAVirusNames);
23683   SetObjectExtra (i, bfp, NULL);
23684 
23685   x = SubMenu (s, "PCR Fixes");
23686   i = CommandItem (x, "Swap Primer Name and Seq Quals", SwapPrimerNamesAndSeq);
23687   SetObjectExtra (i, bfp, NULL);
23688 
23689   i = CommandItem (x, "Trim Junk in Primer Seqs", TrimPrimerSeqJunk);
23690   SetObjectExtra (i, bfp, NULL);
23691 
23692   i = CommandItem (x, "Split PCR Primer Sets by Position", SplitPCRPrimersByPositionMenuItem);
23693   SetObjectExtra (i, bfp, NULL);
23694   i = CommandItem (x, "Split PCR Primer Sets by Constraint", SplitPCRPrimersByConstraintsMenuItem);
23695   SetObjectExtra (i, bfp, NULL);
23696   i = CommandItem (x, "Merge PCR Primer Sets", MergePCRPrimerSetsMenuItem);
23697   SetObjectExtra (i, bfp, NULL);
23698   i = CommandItem (x, "Fix i in PCR Primer Seqs", FixiPCRPrimerSeqsMenuItem);
23699   SetObjectExtra (i, bfp, NULL);
23700 
23701   SeparatorItem (s);
23702   i = CommandItem (s, "Merge Multiple BioSources On Sequence", MergeBiosources);
23703   SetObjectExtra (i, bfp, NULL);
23704 
23705   if (indexerVersion) {
23706     SeparatorItem (s);
23707     i = CommandItem (s, "Compare with BioSample", CompareWithBioSample);
23708     SetObjectExtra (i, bfp, NULL);
23709     i = CommandItem (s, "Compare with BioSample (only first sequence)", CompareWithBioSampleOnlyFirst);
23710     SetObjectExtra (i, bfp, NULL);
23711     i = CommandItem (s, "Make Biosample Update Table", MakeBioSampleUpdateTable);
23712     SetObjectExtra (i, bfp, NULL);
23713     i = CommandItem (s, "Add Missing Fields from BioSample", AddMissingFieldsFromBioSample);
23714     SetObjectExtra (i, bfp, NULL);
23715   }
23716 
23717   SeparatorItem (s);
23718   i = CommandItem (s, "Split Structured Collections at Semicolon", SplitSemicolonedVouchers);
23719   SetObjectExtra (i, bfp, NULL);
23720   i = CommandItem (s, "Split Quals at Commas", SplitQualsAtCommas);
23721   SetObjectExtra (i, bfp, NULL);
23722   i = CommandItem (s, "Split DBLink Quals at Commas", SplitDBLinkFieldsAtCommas);
23723   SetObjectExtra (i, bfp, NULL);
23724 
23725   SeparatorItem (s);
23726   i = CommandItem (s, "Fix caps in mouse strains", FixMouseStrains);
23727   SetObjectExtra (i, bfp, NULL);
23728   if (indexerVersion) {
23729     SeparatorItem (s);
23730     i = CommandItem (s, "Globally Disable Strain Forwarding", GlobalDisableStrainForwarding);
23731     SetObjectExtra (i, bfp, NULL);
23732   }
23733 }
23734 
23735 
MakeSpecialProjectsMenu(MenU s,BaseFormPtr bfp)23736 extern void MakeSpecialProjectsMenu (MenU s, BaseFormPtr bfp)
23737 {
23738   IteM  i;
23739   MenU  x;
23740 
23741   if (indexerVersion) {
23742     i = CommandItem (s, "Create Seq-Hist for TPA", CreateSeqHistTPA);
23743     SetObjectExtra (i, bfp, NULL);
23744     i = CommandItem (s, "Create Seq-Hist for TPA - Detailed",
23745                      CreateSeqHistTPADetailed);
23746     SetObjectExtra (i, bfp, NULL);
23747     i = CommandItem (s, "Advanced Assembly Alignment Editor", AdvancedAssemblyAlignmentEditor);
23748     SetObjectExtra (i, bfp, NULL);
23749     i = CommandItem (s, "Assembly Alignment Interval Resolution", AssemblyAlignmentIntervalResolution);
23750     SetObjectExtra (i, bfp, NULL);
23751     i = CommandItem (s, "Remove Seq-Hist Assembly", RemoveSeqHistAssembly);
23752     SetObjectExtra (i, bfp, NULL);
23753 #ifdef USE_SMARTNET
23754     i = CommandItem (s, "Turn off far fetch from HUP and SMART for TPA validation", DisAllowFarFetchForTPAValidation);
23755     SetObjectExtra (i, bfp, NULL);
23756 #endif
23757     x = SubMenu (s, "Load and Import");
23758     i = CommandItem (x, "Load TPA Accession Numbers From File",
23759                      LoadTPAAccessionNumbersFromFile);
23760     SetObjectExtra (i, bfp, NULL);
23761 
23762 
23763     SeparatorItem (s);
23764     i = CommandItem (s, "BARCODE Discrepancy Tool", BarcodeTestTool);
23765     SetObjectExtra (i, bfp, NULL);
23766     i = CommandItem (s, "Create BARCODE IDs", CreateBarcodeIDsFromLocalIDs);
23767     SetObjectExtra (i, bfp, NULL);
23768     i = CommandItem (s, "Apply BARCODE Dbxrefs", ApplyBarcodeDbxrefs);
23769     SetObjectExtra (i, bfp, NULL);
23770     i = CommandItem (s, "Apply FBOL Dbxrefs", ApplyFBOLDbxrefs);
23771     SetObjectExtra (i, bfp, NULL);
23772     i = CommandItem (s, "Check for rbcL and matK matches", ScreenBarcodePlant);
23773     SetObjectExtra (i, bfp, NULL);
23774 
23775     SeparatorItem (s);
23776 
23777     x = SubMenu (s, "Create TSA IDs");
23778     i = CommandItem (x, "From Existing IDs", CreateTSAIDsFromLocalIDs);
23779     SetObjectExtra (i, bfp, NULL);
23780     i = CommandItem (x, "From Table", CreateTSAIDsFromTable);
23781     SetObjectExtra (i, bfp, NULL);
23782     i = CommandItem (x, "From Existing IDs with Suffix", CreateTSAIDsFromLocalIDsWithSuffix);
23783     SetObjectExtra (i, bfp, NULL);
23784     i = CommandItem (x, "From Defline", CreateTSAIDsFromDefline);
23785     SetObjectExtra (i, bfp, NULL);
23786 
23787     i = CommandItem (s, "Trim for N Pct", FindBestNTrimSites);
23788     SetObjectExtra (i, bfp, NULL);
23789     SeparatorItem (s);
23790     i = CommandItem (s, "Add Flu Comments", AddFluComments);
23791     SetObjectExtra (i, bfp, NULL);
23792 
23793     SeparatorItem (s);
23794     i = CommandItem (s, "Propagate Missing Old-name Quals", PropagateMissingOldNameQualsItem);
23795     SetObjectExtra (i, bfp, NULL);
23796 
23797     if (indexerVersion) {
23798       SeparatorItem (s);
23799       i = CommandItem (s, "Set Global RefGene Status", SetGlobalRefGeneStatus);
23800       SetObjectExtra (i, bfp, NULL);
23801     }
23802 
23803     /* remove after retro */
23804     SeparatorItem (s);
23805     i = CommandItem (s, "GI to dbSTS Conversion", DoGI2dbSTSConversion);
23806     SetObjectExtra (i, bfp, NULL);
23807 
23808     SeparatorItem(s);
23809     i = CommandItem (s, "Convert Bad Coding Regions and RNA features to misc_feat", ConvertBadToMiscFeat);
23810     SetObjectExtra (i, bfp, NULL);
23811   }
23812 }
23813 
MakeSpecialLocusTagMenu(MenU m,BaseFormPtr bfp)23814 static void MakeSpecialLocusTagMenu (MenU m, BaseFormPtr bfp)
23815 {
23816   IteM  i;
23817   MenU  s;
23818 
23819   s = SubMenu (m, "Locus_Tags");
23820   i = CommandItem (s, "Insert Gene Locus Tag Prefix", InsertGeneLocusTagPrefix);
23821   SetObjectExtra (i, bfp, NULL);
23822   SeparatorItem (s);
23823   i = CommandItem (s, "Convert Gene Locus Tag to Old Locus Tag", ConvertLocusTagToOldLocusTag);
23824   SetObjectExtra (i, bfp, NULL);
23825 
23826   SeparatorItem (s);
23827   i = CommandItem (s, "Create Protein IDs", CreateProteinIDs);
23828   SetObjectExtra (i, bfp, NULL);
23829   i = CommandItem (s, "Create Locus Tag Genes", AddLocusTagGenes);
23830   SetObjectExtra (i, bfp, NULL);
23831 }
23832 
23833 
MakeSpecialApplyMenu(MenU m,BaseFormPtr bfp)23834 static void MakeSpecialApplyMenu (MenU m, BaseFormPtr bfp)
23835 {
23836   IteM  i;
23837   MenU  s, x;
23838 
23839   s = SubMenu (m, "Apply/ A");
23840   i = CommandItem (s, "Add CDS", ApplyCDS);
23841   SetObjectExtra (i, bfp, NULL);
23842   i = CommandItem (s, "Add RNA", ApplyRRNA);
23843   SetObjectExtra (i, bfp, NULL);
23844   x = SubMenu (s, "Add Named rRNA");
23845   i = CommandItem (x, "12S", Apply12SRNA);
23846   SetObjectExtra (i, bfp, NULL);
23847   i = CommandItem (x, "16S", Apply16SRNA);
23848   SetObjectExtra (i, bfp, NULL);
23849   i = CommandItem (x, "23S", Apply23SRNA);
23850   SetObjectExtra (i, bfp, NULL);
23851   i = CommandItem (x, "18S", Apply18SRNA);
23852   SetObjectExtra (i, bfp, NULL);
23853   i = CommandItem (x, "28S", Apply28SRNA);
23854   SetObjectExtra (i, bfp, NULL);
23855   i = CommandItem (x, "26S", Apply26SRNA);
23856   SetObjectExtra (i, bfp, NULL);
23857   i = CommandItem (x, "Small", ApplySmallRNA);
23858   SetObjectExtra (i, bfp, NULL);
23859   i = CommandItem (x, "Large", ApplyLargeRNA);
23860   SetObjectExtra (i, bfp, NULL);
23861   i = CommandItem (s, "Apply rRNA_ITS", ApplyRNA_ITS);
23862   SetObjectExtra (i, bfp, NULL);
23863   /*
23864   i = CommandItem (s, "Label Fungal rRNAs", LabelFungalRNAs);
23865   SetObjectExtra (i, bfp, NULL);
23866   */
23867   i = CommandItem (s, "Label rRNAs", LabelNewRNAs);
23868   SetObjectExtra (i, bfp, NULL);
23869 
23870   i = CommandItem (s, "Add other Feature", ApplyImpFeat);
23871   SetObjectExtra (i, bfp, NULL);
23872   x = SubMenu (s, "Add Common Feature");
23873   i = CommandItem (x, "Microsatellite", MakeCommonFeatureMicrosatellite);
23874   SetObjectExtra (i, bfp, NULL);
23875   i = CommandItem (x, "Control Region", MakeCommonFeatureControlRegion);
23876   SetObjectExtra (i, bfp, NULL);
23877   i = CommandItem (s, "Add Feature Between", AddFeatureBetween);
23878   SetObjectExtra (i, bfp, NULL);
23879 
23880   i = CommandItem (s, "Add Qualifier", MacroApplyGBQual);
23881   SetObjectExtra (i, bfp, NULL);
23882   SeparatorItem (s);
23883   i = CommandItem (s, "Add Source Qual", MacroApplySourceQual);
23884   SetObjectExtra (i, bfp, NULL);
23885   i = CommandItem (s, "Add CDS-Gene-Prot-mRNA Qual", MacroApplyCDSGeneProt);
23886   SetObjectExtra (i, bfp, NULL);
23887   i = CommandItem (s, "Add RNA Qual", MacroApplyRNAQual);
23888   SetObjectExtra (i, bfp, NULL);
23889   SeparatorItem (s);
23890   i = CommandItem (s, "Add Molecule Information", ApplyMolInfo);
23891   SetObjectExtra (i, bfp, NULL);
23892   SeparatorItem (s);
23893   x = SubMenu (s, "Add Gene Pseudo");
23894   i = CommandItem (x, "With String Constraint", AddGenePseudo);
23895   SetObjectExtra (i, bfp, NULL);
23896   i = CommandItem (x, "Where Feature is Pseudo", MarkGenesWithPseudoFeaturesPseudo);
23897   SetObjectExtra (i, bfp, NULL);
23898   i = CommandItem (s, "Add Global Code Break", AddGlobalCodeBreak);
23899   SetObjectExtra (i, bfp, NULL);
23900   if (indexerVersion)
23901   {
23902     x = SubMenu (s, "Add Keyword");
23903     i = CommandItem (x, "GDS", ApplyGDSKeyword);
23904     SetObjectExtra (i, bfp, NULL);
23905     i = CommandItem (x, "TPA:inferential", ApplyTPAInferentialKeyword);
23906     SetObjectExtra (i, bfp, NULL);
23907     i = CommandItem (x, "TPA:experimental", ApplyTPAExperimentalKeyword);
23908     SetObjectExtra (i, bfp, NULL);
23909     i = CommandItem (x, "TPA:assembly", ApplyTPAReassemblyKeyword);
23910     SetObjectExtra (i, bfp, NULL);
23911     i = CommandItem (x, "With Constraint", ApplyKeywordWithStringConstraint);
23912     SetObjectExtra (i, bfp, NULL);
23913     i = CommandItem (x, "Structured Comment", AddStructuredCommentKeywordsMenuItem);
23914     SetObjectExtra (i, bfp, NULL);
23915   }
23916   else
23917   {
23918     i = CommandItem (s, "Add GDS Keyword", ApplyGDSKeyword);
23919     SetObjectExtra (i, bfp, NULL);
23920   }
23921   SeparatorItem(s);
23922   if (indexerVersion) {
23923     SetupEditSecondary (s, bfp);
23924   }
23925   x = SubMenu (s, "Load Secondary Accessions from File");
23926   i = CommandItem (x, "Extra Accessions",
23927                    LoadSecondaryAccessionNumbersFromFile);
23928   SetObjectExtra (i, bfp, NULL);
23929   i = CommandItem (x, "History Takeover",
23930                    LoadHistoryAccessionNumbersFromFile);
23931   SetObjectExtra (i, bfp, NULL);
23932   SeparatorItem (s);
23933   i = CommandItem (s, "Load Genome Project IDs from File", LoadGenomeProjectIDsFromFile);
23934   SetObjectExtra (i, bfp, NULL);
23935   SeparatorItem (s);
23936 
23937   i = CommandItem (s, "Load Feature Qualifiers from File",
23938                    LoadFeatureQualifierTable);
23939   SetObjectExtra (i, bfp, NULL);
23940 
23941   i = CommandItem (s, "Load Feature Fields from File", LoadFeatureFieldTable);
23942   SetObjectExtra (i, bfp, NULL);
23943   i = CommandItem (s, "Table Reader", NewLoadFeatureQualifierTable);
23944   SetObjectExtra (i, bfp, NULL);
23945   i = CommandItem (s, "Table Reader from Clipboard", NewLoadFeatureQualifierTableFromClipboard);
23946   SetObjectExtra (i, bfp, NULL);
23947   i = CommandItem (s, "Export Table", ExportQualifiers);
23948   SetObjectExtra (i, bfp, NULL);
23949   i = CommandItem (s, "Export Bankit Comments", ExportBankitComments);
23950   SetObjectExtra (i, bfp, NULL);
23951   i = CommandItem (s, "Apply Indexer Comments", AddIndexerCommentMenuItem);
23952   SetObjectExtra (i, bfp, NULL);
23953 
23954   SeparatorItem (s);
23955   i = CommandItem (s, "Propagate DBLink Descriptors", PropagateDblinkDescriptorsMenuItem);
23956   SetObjectExtra (i, bfp, NULL);
23957 }
23958 
23959 
MakeSpecialRemoveMenu(MenU m,BaseFormPtr bfp)23960 static void MakeSpecialRemoveMenu (MenU m, BaseFormPtr bfp)
23961 {
23962   IteM  i;
23963   MenU  s, x, y;
23964 
23965   s = SubMenu (m, "Remove/ R");
23966   i = CommandItem (s, "Remove Descriptors", RemoveDescriptor);
23967   SetObjectExtra (i, bfp, NULL);
23968   i = CommandItem (s, "Remove Features", FeatureRemove);
23969   SetObjectExtra (i, bfp, NULL);
23970 
23971   x = SubMenu (s, "Remove Features by Selection");
23972   i = CommandItem (x, "Selected", RemoveSelFeats);
23973   SetObjectExtra (i, bfp, NULL);
23974   i = CommandItem (x, "Unselected", RemoveUnselFeats);
23975   SetObjectExtra (i, bfp, NULL);
23976   i = CommandItem (x, "All Features Outside Range of Selected Feature", RemoveFeatsOutOfSelRange);
23977   SetObjectExtra (i, bfp, NULL);
23978 
23979   i = CommandItem (s, "Remove Unindexed Features", RemoveUnindexedFeatures);
23980   SetObjectExtra (i, bfp, NULL);
23981 
23982   i = CommandItem (s, "Remove Genes by Features", RemoveGeneByUnderlyingFeatureType);
23983   SetObjectExtra (i, bfp, NULL);
23984   SeparatorItem (s);
23985   i = CommandItem (s, "Remove RBSs Genes", RemoveRBSGenes);
23986   SetObjectExtra (i, bfp, NULL);
23987   SeparatorItem (s);
23988 
23989   i = CommandItem (s, "Remove Qualifiers", MacroRemoveGBQual);
23990   SetObjectExtra (i, bfp, NULL);
23991 
23992   i = CommandItem (s, "Remove Source Qualifier", MacroRemoveSourceQual);
23993   SetObjectExtra (i, bfp, NULL);
23994 
23995   i = CommandItem (s, "Remove Uncultured Notes", RemoveUnculturedNotesMenuItem);
23996   SetObjectExtra (i, bfp, NULL);
23997 
23998   i = CommandItem (s, "Remove Unverified", RemoveUnverified);
23999   SetObjectExtra (i, bfp, NULL);
24000 
24001   i = CommandItem (s, "Remove CDS-Gene-Prot-mRNA Qual", MacroRemoveCDSGeneProt);
24002   SetObjectExtra (i, bfp, NULL);
24003 
24004   i = CommandItem (s, "Remove RNA Qual", MacroRemoveRNAQual);
24005   SetObjectExtra (i, bfp, NULL);
24006 
24007   i = CommandItem (s, "Remove Illegal Qualifiers", RemoveIllegalQuals);
24008   SetObjectExtra (i, bfp, NULL);
24009 
24010   i = CommandItem (s, "Remove Wrong Qualifiers", RemoveWrongQuals);
24011   SetObjectExtra (i, bfp, NULL);
24012 
24013   i = CommandItem (s, "Remove bad tRNA codon-recognized Qualifiers", RemoveBadCodonRecognized);
24014   SetObjectExtra (i, bfp, NULL);
24015 
24016   i = CommandItem (s, "Remove Seq-annot.data.ids", RemoveSeqAnnotDataIds);
24017   SetObjectExtra (i, bfp, NULL);
24018 
24019   SeparatorItem (s);
24020 
24021   x = SubMenu (s, "Remove Proteins");
24022   i = CommandItem (x, "Just Remove Proteins", RemoveProteins);
24023   SetObjectExtra (i, bfp, NULL);
24024   i = CommandItem (x, "And Renormalize Nuc-Prot Sets", RemoveProteinsAndRenormalize);
24025   SetObjectExtra (i, bfp, NULL);
24026   i = CommandItem (x, "Orphaned Proteins", RemoveOrphanedProteins);
24027   SetObjectExtra (i, bfp, NULL);
24028 
24029   x = SubMenu (s, "Remove CDD");
24030   i = CommandItem (x, "Regions", RemoveCDDRegions);
24031   SetObjectExtra (i, bfp, NULL);
24032   i = CommandItem (x, "Alignments", RemoveCDDAligns);
24033   SetObjectExtra (i, bfp, NULL);
24034   i = CommandItem (x, "Duplicates", RemoveCDDDups);
24035   SetObjectExtra (i, bfp, NULL);
24036   i = CommandItem (x, "Overlapping (Retain Best)", RetainBestCDD);
24037   SetObjectExtra (i, bfp, NULL);
24038   i = CommandItem (s, "Remove Nth Seg's CDS for Each SegSet",
24039 		   RemoveNthCDSFromSegSets_Callback);
24040   SetObjectExtra (i, bfp, NULL);
24041   i = CommandItem (x, "Remove All CDD Features and Dbxrefs", CleanupCDD);
24042   SetObjectExtra (i, bfp, NULL);
24043   SeparatorItem (s);
24044 
24045   i = CommandItem (s, "Remove BankIt Comments", RemoveBankitComments);
24046   SetObjectExtra (i, bfp, NULL);
24047 
24048   SeparatorItem (s);
24049 
24050   x = SubMenu (s, "Remove Text");
24051   i = CommandItem (x, "Inside String", RemoveTextInsideString);
24052   SetObjectExtra (i, bfp, NULL);
24053   i = CommandItem (x, "Outside String", NewRemoveTextOutsideString);
24054   SetObjectExtra (i, bfp, NULL);
24055 
24056   SeparatorItem (s);
24057 
24058   x = SubMenu (s, "Remove Duplicate");
24059   i = CommandItem (x, "All Feat Types", NewRemoveDuplicateFeatsAll);
24060   SetObjectExtra (i, bfp, NULL);
24061   i = CommandItem (x, "Feats With Options", RemoveDuplicateFeatsWithOptions);
24062   SetObjectExtra (i, bfp, NULL);
24063   i = CommandItem (x, "Gene Ontology Terms", RemoveDuplicateGeneOntology);
24064   SetObjectExtra (i, bfp, NULL);
24065   i = CommandItem (x, "Structured Comments", RemoveDuplicateStructuredComments);
24066   SetObjectExtra (i, bfp, NULL);
24067 
24068   i = CommandItem (s, "Remove Redundant Proprotein Misc Feats",
24069                    RemoveRedundantProproteinMiscFeats);
24070   SetObjectExtra (i, bfp, NULL);
24071 
24072   SeparatorItem (s);
24073 
24074   x = SubMenu (s, "Remove Sequences");
24075   i = CommandItem (x, "From Alignments", RemoveSequencesFromAlignment);
24076   SetObjectExtra (i, bfp, NULL);
24077   i = CommandItem (x, "From Record", RemoveSequencesFromRecord);
24078   SetObjectExtra (i, bfp, NULL);
24079 
24080   i = CommandItem (s, "Remove Alignments", RemoveAlignment);
24081   SetObjectExtra (i, bfp, NULL);
24082   i = CommandItem (s, "Remove Graphs", RemoveGraph);
24083   SetObjectExtra (i, bfp, NULL);
24084 
24085   SeparatorItem (s);
24086 
24087   x = SubMenu (s, "Remove Xrefs");
24088   y = SubMenu (x, "Gene Xrefs");
24089   i = CommandItem (y, "Choose Types and Constraint", NewRemoveGeneXrefs);
24090   SetObjectExtra (i, bfp, NULL);
24091   i = CommandItem (y, "Unnecessary Gene Xrefs", RemoveGeneXrefs);
24092   SetObjectExtra (i, bfp, NULL);
24093   i = CommandItem (y, "Non-Suppressing Gene Xrefs", RemoveNSGeneXrefs);
24094   SetObjectExtra (i, bfp, NULL);
24095   i = CommandItem (y, "Gene Xrefs with Orphan Gene Locus", RemoveGeneXrefsNoGene);
24096   SetObjectExtra (i, bfp, NULL);
24097   i = CommandItem (y, "Gene Xrefs with Orphan Locus_tag", RemoveGeneXrefsNoLocTag);
24098   SetObjectExtra (i, bfp, NULL);
24099   i = CommandItem (y, "ALL Gene Xrefs", RemoveAllGeneXrefs);
24100   SetObjectExtra (i, bfp, NULL);
24101 
24102   y = SubMenu (x, "Taxon Xrefs");
24103   i = CommandItem (y, "From Features", RemoveTaxonXrefsFromFeatures);
24104   SetObjectExtra (i, bfp, NULL);
24105   i = CommandItem (y, "From Features and BioSources",
24106                    RemoveTaxonXrefsFromFeaturesAndBioSources);
24107   SetObjectExtra (i, bfp, NULL);
24108 
24109   y = SubMenu (x, "Db_xrefs");
24110   i = CommandItem (y, "From Genes", RemoveGeneDbxrefs);
24111   SetObjectExtra (i, bfp, NULL);
24112   i = CommandItem (y, "From RNAs", RemoveRNADbxrefs);
24113   SetObjectExtra (i, bfp, NULL);
24114   i = CommandItem (y, "From CDSs", RemoveCDSDbxrefs);
24115   SetObjectExtra (i, bfp, NULL);
24116   i = CommandItem (y, "From All Features", RemoveAllFeatureDbxrefs);
24117   SetObjectExtra (i, bfp, NULL);
24118   i = CommandItem (y, "From All BioSources", RemoveAllBioSourceDbxrefs);
24119   SetObjectExtra (i, bfp, NULL);
24120   i = CommandItem (y, "From All Features and BioSources", RemoveAllDbxrefs);
24121   SetObjectExtra (i, bfp, NULL);
24122 
24123   y = SubMenu (x, "Feature Xrefs");
24124   i = CommandItem (y, "For Missing Features", RemoveMissingFeatureXrefs);
24125   SetObjectExtra (i, bfp, NULL);
24126 
24127   SeparatorItem (s);
24128   y = SubMenu (s, "Remove Titles");
24129   x = SubMenu (y, "Protein");
24130   i = CommandItem (x, "All but RefSeq", DoRemoveProtTitles);
24131   SetObjectExtra (i, bfp, NULL);
24132   i = CommandItem (x, "All", DoRemoveAllProtTitles);
24133   SetObjectExtra (i, bfp, NULL);
24134   i = CommandItem (x, "Hypothetical", RemoveHypotheticalProteinTitles);
24135   SetObjectExtra (i, bfp, NULL);
24136   i = CommandItem (x, "Inconsistent", RemoveInconsistentProteinTitles);
24137   SetObjectExtra (i, bfp, NULL);
24138   x = SubMenu (y, "Nucleotide");
24139   i = CommandItem (x, "All", DoRemoveAllNucTitles);
24140   SetObjectExtra (i, bfp, NULL);
24141   i = CommandItem (x, "mRNA", DoRemoveMrnaTitles);
24142   SetObjectExtra (i, bfp, NULL);
24143   i = CommandItem (x, "NPS", DoRemoveNPSTitles);
24144   SetObjectExtra (i, bfp, NULL);
24145   SeparatorItem (s);
24146 
24147   if (indexerVersion) {
24148     y = SubMenu (s, "Remove IDs, SeqIDs, GI_IDs, LOCUS");
24149     x = SubMenu (y, "Local");
24150     i = CommandItem (x, "From Nucleotides", RemoveNucLocalIDs);
24151     SetObjectExtra (i, bfp, NULL);
24152     i = CommandItem (x, "From Proteins", RemovePrtLocalIDs);
24153     SetObjectExtra (i, bfp, NULL);
24154     i = CommandItem (x, "From All Bioseqs", RemoveLocalIDs);
24155     SetObjectExtra (i, bfp, NULL);
24156 
24157     x = SubMenu (y, "GenBank");
24158     i = CommandItem (x, "From Proteins", RemoveGBIDsFromProteins);
24159     SetObjectExtra (i, bfp, NULL);
24160     i = CommandItem (x, "From All Bioseqs", RemoveGBIDsFromBioseqs);
24161     SetObjectExtra (i, bfp, NULL);
24162 
24163     i = CommandItem (y, "Seq-ID Name From Prot Feats", RemoveSeqIdName_Callback);
24164     SetObjectExtra (i, bfp, NULL);
24165 
24166     i = CommandItem (y, "GI_IDs from Bioseqs", RemoveGIsFromBioseqs);
24167     SetObjectExtra (i, bfp, NULL);
24168 
24169     i = CommandItem (y, "LOCUS from Parts", RemoveLocusFromParts);
24170     SetObjectExtra (i, bfp, NULL);
24171 
24172     i = CommandItem (y, "TSA IDs", RemoveTSAIdsFromBioseqs);
24173     SetObjectExtra (i, bfp, NULL);
24174     i = CommandItem (y, "General IDs", RemoveGeneralIds);
24175     SetObjectExtra (i, bfp, NULL);
24176 
24177     SeparatorItem (s);
24178   }
24179 
24180   i = CommandItem (s, "Remove Empty Genome Project ID Descriptors", RemoveEmptyGenomeProjectIDs);
24181   SetObjectExtra (i, bfp, NULL);
24182   i = CommandItem (s, "Remove All Genome Project IDs", RemoveGenomeProjectIDs);
24183   SetObjectExtra (i, bfp, NULL);
24184 
24185   SeparatorItem (s);
24186   i = CommandItem (s, "Withdraw Sequences", WithdrawSequences);
24187   SetObjectExtra (i, bfp, NULL);
24188 
24189 }
24190 
MakeSpecialConvertMenu(MenU m,BaseFormPtr bfp)24191 static void MakeSpecialConvertMenu (MenU m, BaseFormPtr bfp)
24192 {
24193   IteM  i;
24194   MenU  s, x, y, z;
24195 
24196   s = SubMenu (m, "Convert/ C");
24197   i = CommandItem (s, "Convert Features", ConvertFeatures);
24198   SetObjectExtra (i, bfp, NULL);
24199 
24200   i = CommandItem (s, "Convert Qualifiers", MacroConvertGBQual);
24201   SetObjectExtra (i, bfp, NULL);
24202 
24203   SeparatorItem (s);
24204   i = CommandItem (s, "Convert Source Qualifier", MacroConvertSourceQual);
24205   SetObjectExtra (i, bfp, NULL);
24206 
24207   i = CommandItem (s, "Convert CDS-Gene-Prot-mRNA Qual", MacroConvertCDSGeneProt);
24208   SetObjectExtra (i, bfp, NULL);
24209 
24210   i = CommandItem (s, "Convert RNA Qual", MacroConvertRNAQual);
24211   SetObjectExtra (i, bfp, NULL);
24212 
24213   i = CommandItem (s, "Convert Illegal Qualifiers to Note", MoveIllegalQuals);
24214   SetObjectExtra (i, bfp, NULL);
24215 
24216   i = CommandItem (s, "Convert Wrong Qualifiers to Note", MoveWrongQuals);
24217   SetObjectExtra (i, bfp, NULL);
24218 
24219   SeparatorItem (s);
24220 
24221   i = CommandItem (s, "Convert CDS to Misc_feat or Pseudogene", ConvertCDSMenuItem);
24222   SetObjectExtra (i, bfp, NULL);
24223   x = SubMenu (s, "Convert CDS with Internal Stop Codon");
24224   i = CommandItem (x, "To Misc Feat", NewConvertCDSWithInternalStopsToMiscFeat);
24225   SetObjectExtra (i, bfp, NULL);
24226   i = CommandItem (x, "To Misc Feat (Viral)", NewConvertCDSWithInternalStopsToMiscFeatViral);
24227   SetObjectExtra (i, bfp, NULL);
24228   i = CommandItem (x, "To Misc Feat with Unverified Comment", ConvertCDSWithInternalStopsToMiscFeatWithUnverified);
24229   SetObjectExtra (i, bfp, NULL);
24230 
24231   i = CommandItem (s, "Convert Bad Inference Qualifiers to Notes", ConvertBadInferenceToNote);
24232   SetObjectExtra (i, bfp, NULL);
24233 
24234   i = CommandItem (s, "Convert transl-except in CDSs to RNA Editing Exception", ConvertTranslExceptToRNAEditingException);
24235   SetObjectExtra (i, bfp, NULL);
24236 
24237   i = CommandItem (s, "Convert to Delayed Gen-Prod-Set Qualifiers", ConvertToDelayedGenProdSetQualifiers);
24238   SetObjectExtra (i, bfp, NULL);
24239 
24240   SeparatorItem (s);
24241 
24242   i = CommandItem (s, "Swap Source Qualifiers", MacroSwapSourceQual);
24243   SetObjectExtra (i, bfp, NULL);
24244   i = CommandItem (s, "Swap CDS-Gene-Prot-mRNA Qualifiers", MacroSwapCDSGeneProt);
24245   SetObjectExtra (i, bfp, NULL);
24246   i = CommandItem (s, "Swap RNA Qualifiers", MacroSwapRNAQual);
24247   SetObjectExtra (i, bfp, NULL);
24248   i = CommandItem (s, "Swap Qualifiers", MacroSwapGBQual);
24249   SetObjectExtra (i, bfp, NULL);
24250 
24251 
24252 
24253   SeparatorItem (s);
24254 
24255   i = CommandItem (s, "Parse Text", ParseFlatfileToSourceQual);
24256   SetObjectExtra (i, bfp, NULL);
24257   SeparatorItem (s);
24258 
24259   x = SubMenu (s, "Parse from tRNA Comment");
24260   i = CommandItem (x, "Codons", ParseCodonsFromtRNAComment);
24261   SetObjectExtra (i, bfp, NULL);
24262   i = CommandItem (x, "Anticodons", ParseAntiCodonsFromtRNAComment);
24263   SetObjectExtra (i, bfp, NULL);
24264 
24265   i = CommandItem (s, "Parse Codon Quals to Code Breaks", ParseCodonQualToCodeBreak);
24266   SetObjectExtra (i, bfp, NULL);
24267 
24268   SeparatorItem (s);
24269 
24270   x = SubMenu (s, "Convert Descriptors and Features");
24271 
24272   y = SubMenu (x, "Descriptor to Feature");
24273   i = CommandItem (y, "Source", ConvertSrcDescToFeat);
24274   SetObjectExtra (i, bfp, NULL);
24275   i = CommandItem (y, "Comment", ConvertComDescToFeat);
24276   SetObjectExtra (i, bfp, NULL);
24277   z = SubMenu (y, "Publication");
24278   i = CommandItem (z, "All", ConvertPubDescToFeat);
24279   SetObjectExtra (i, bfp, NULL);
24280   i = CommandItem (z, "By Constraint", CreateConvertPubDescStringConstraintDialogX);
24281   SetObjectExtra (i, bfp, NULL);
24282 
24283   y = SubMenu (x, "Convert Full Length Feature to Descriptor");
24284   i = CommandItem (y, "Source", ConvertSrcFeatToDesc);
24285   SetObjectExtra (i, bfp, NULL);
24286   i = CommandItem (y, "Comment", ConvertCommentFeatToDesc);
24287   SetObjectExtra (i, bfp, NULL);
24288   i = CommandItem (y, "Publication", ConvertPubFeatToDesc);
24289   SetObjectExtra (i, bfp, NULL);
24290 
24291   i = CommandItem (x, "BankIt Comment to Comment Descriptor", CopyBankitComments);
24292   SetObjectExtra (i, bfp, NULL);
24293 
24294   SeparatorItem (s);
24295   x = SubMenu (s, "Convert Second Protein Name and Description");
24296   i = CommandItem (x, "Second Protein Name to Description", SecondProtNameToDesc);
24297   SetObjectExtra (i, bfp, NULL);
24298   i = CommandItem (x, "Protein Description to Second Name", ProtDescToSecondName);
24299   SetObjectExtra (i, bfp, NULL);
24300   SeparatorItem (s);
24301   if (indexerVersion) {
24302     i = CommandItem (s, "Convert repeat_region rpt_unit_range to location", ConvertRptUnitRangeToLocation);
24303     SetObjectExtra (i, bfp, NULL);
24304     i = CommandItem (s, "Flip codon_recognized where listed as anticodon", FlipCodonRecognized);
24305     SetObjectExtra (i, bfp, NULL);
24306     SeparatorItem (s);
24307   }
24308   i = CommandItem (s, "Both Strands to Proper Strand", ConvertBothStrands);
24309   SetObjectExtra (i, bfp, NULL);
24310   SeparatorItem (s);
24311   i = CommandItem (s, "Refresh Gene Xrefs", RefreshGeneXRefs);
24312   SetObjectExtra (i, bfp, NULL);
24313   SeparatorItem (s);
24314   i = CommandItem (s, "Convert Biosource Dbxrefs to Feature Dbxrefs", ConvertBioSourceDbxrefToFeatureDbxref);
24315   SetObjectExtra (i, bfp, NULL);
24316   SeparatorItem (s);
24317 #if 0
24318   i = CommandItem (s, "Convert SegSets to Delta Sequences", ConvertSegSetToDeltaItem);
24319   SetObjectExtra (i, bfp, NULL);
24320   SeparatorItem (s);
24321 #endif
24322   if (indexerVersion) {
24323     x = SubMenu (s, "Convert IDs, Accessions, or GenBank.names");
24324     i = CommandItem (x, "LocalIDs to GeneralIDs", ConvertLocalToGeneral);
24325     SetObjectExtra (i, bfp, NULL);
24326     i = CommandItem (x, "GeneralIDs to LocalIDs", ConvertGeneralIdToLocalID);
24327     SetObjectExtra (i, bfp, NULL);
24328     y = SubMenu (x, "Accession to LocalIDs");
24329     i = CommandItem (y, "For All Sequences", ConvertToLocalProcAll);
24330     SetObjectExtra (i, bfp, NULL);
24331     i = CommandItem (y, "For Nucleotide Sequences", ConvertToLocalProcOnlyNucs);
24332     SetObjectExtra (i, bfp, NULL);
24333     i = CommandItem (y, "For Protein Sequences", ConvertToLocalProcOnlyProts);
24334     SetObjectExtra (i, bfp, NULL);
24335     i = CommandItem (x, "GenBank.name to LocalID", ChangeGenBankNameToLocal);
24336     SetObjectExtra (i, bfp, NULL);
24337   }
24338 }
24339 
24340 
MakeSpecialEditMenu(MenU m,BaseFormPtr bfp)24341 static void MakeSpecialEditMenu (MenU m, BaseFormPtr bfp)
24342 {
24343   IteM  i;
24344   MenU  s, x;
24345 
24346   s = SubMenu (m, "Edit/ E");
24347   i = CommandItem (s, "Edit Qualifiers", MacroEditGBQual);
24348   SetObjectExtra (i, bfp, NULL);
24349   i = CommandItem (s, "Edit Source Qual", MacroEditSourceQual);
24350   SetObjectExtra (i, bfp, NULL);
24351   i = CommandItem (s, "Edit CDS-Gene-Prot-mRNA Qual", MacroEditCDSGeneProt);
24352   SetObjectExtra (i, bfp, NULL);
24353   i = CommandItem (s, "Edit RNA Qual", MacroEditRNAQual);
24354   SetObjectExtra (i, bfp, NULL);
24355   SeparatorItem (s);
24356   i = CommandItem (s, "Edit Molecule Information", NewMolInfoFieldsEdit);
24357   SetObjectExtra (i, bfp, NULL);
24358   SeparatorItem (s);
24359   x = SubMenu (s, "Edit Feature");
24360   i = CommandItem (x, "Evidence", FeatureEvidenceEditor);
24361   SetObjectExtra (i, bfp, NULL);
24362   i = CommandItem (x, "Exception", FeatureExceptionEditor);
24363   SetObjectExtra (i, bfp, NULL);
24364   i = CommandItem (x, "Location", FeaturePartialEditor);
24365   SetObjectExtra (i, bfp, NULL);
24366   i = CommandItem (x, "Strand", FeatureStrandEditor);
24367   SetObjectExtra (i, bfp, NULL);
24368   i = CommandItem (x, "Citation", FeatureCitationEditor);
24369   SetObjectExtra (i, bfp, NULL);
24370   i = CommandItem (x, "Experiment", FeatureExperimentEditor);
24371   SetObjectExtra (i, bfp, NULL);
24372   i = CommandItem (x, "Inference", FeatureInferenceEditor);
24373   SetObjectExtra (i, bfp, NULL);
24374   i = CommandItem (x, "Pseudo", FeaturePseudoEditor);
24375   SetObjectExtra (i, bfp, NULL);
24376   i = CommandItem (x, "Reverse Location Interval Order", ReverseFeatureIntervals);
24377   SetObjectExtra (i, bfp, NULL);
24378   i = CommandItem (x, "Resolve Intersecting Feature Locations", ResolveFeatureOverlaps);
24379   SetObjectExtra (i, bfp, NULL);
24380   i = CommandItem (x, "Update Features", UpdateFeatures);
24381   SetObjectExtra (i, bfp, NULL);
24382   i = CommandItem (x, "Extend Coding Region Ends", ExtendCodingRegionEnds);
24383   SetObjectExtra (i, bfp, NULL);
24384   i = CommandItem (x, "New Feature Location Editor", NewFeatureLocationEditor);
24385   SetObjectExtra (i, bfp, NULL);
24386 
24387   SeparatorItem (s);
24388   x = SubMenu (s, "Bulk Edit");
24389   i = CommandItem (x, "CDS", BulkEditCDS);
24390   SetObjectExtra (i, bfp, NULL);
24391   i = CommandItem (x, "Gene", BulkEditGene);
24392   SetObjectExtra (i, bfp, NULL);
24393   i = CommandItem (x, "RNA", BulkEditRNA);
24394   SetObjectExtra (i, bfp, NULL);
24395   i = CommandItem (x, "Source", BulkEditSource);
24396   SetObjectExtra (i, bfp, NULL);
24397 
24398   SeparatorItem (s);
24399   x = SubMenu (s, "Macro");
24400   i = CommandItem (x, "Macro Editor", LaunchMacroEditorMenuItem);
24401   SetObjectExtra (i, bfp, NULL);
24402   i = CommandItem (x, "Macro Template Editor", LaunchMacroTemplateEditor);
24403   SetObjectExtra (i, bfp, NULL);
24404 #if 1
24405   i = CommandItem (x, "Suspect Product Rule Editor", LaunchSuspectProductRuleEditor);
24406   SetObjectExtra (i, bfp, NULL);
24407 #endif
24408   i = CommandItem (x, "AutoFix", RunAutoFixScriptMenuItem);
24409   SetObjectExtra (i, bfp, NULL);
24410   i = CommandItem (x, "AutoFix Window", RunAutoFixWindowMenuItem);
24411   SetObjectExtra (i, bfp, NULL);
24412 
24413   SeparatorItem (s);
24414   i = CommandItem (s, "Lowercase Qualifiers", ChangeQualifierCase);
24415   SetObjectExtra (i, bfp, NULL);
24416 
24417   SeparatorItem (s);
24418   x = SubMenu (s, "Extend Partial Features");
24419   i = CommandItem (x, "All to Ends", ExtendPartialFeatures);
24420   SetObjectExtra (i, bfp, NULL);
24421   i = CommandItem (x, "With Constraint", ExtendPartialFeaturesWithConstraint);
24422   SetObjectExtra (i, bfp, NULL);
24423 
24424   i = CommandItem (s, "Extend Gene", ExtendGeneReg);
24425   SetObjectExtra (i, bfp, NULL);
24426   SeparatorItem (s);
24427   i = CommandItem (s, "Correct Genes for CDSs or mRNAs", CorrectGenes);
24428   SetObjectExtra (i, bfp, NULL);
24429   i = CommandItem (s, "Correct Strand for primer_bind Pairs", SetPrimerBindPairStrands);
24430   SetObjectExtra (i, bfp, NULL);
24431   if (indexerVersion) {
24432     SeparatorItem (s);
24433     i = CommandItem (s, "Edit Locus", EditLocusProc);
24434     SetObjectExtra (i, bfp, NULL);
24435 
24436     SeparatorItem (s);
24437     i = CommandItem (s, "Edit Sequence Ends", EditSeqEndsProc);
24438     SetObjectExtra (i, bfp, NULL);
24439 
24440     i = CommandItem (s, "Edit Sequence Ends with Alignment", TrimSequencesByAlignment);
24441     SetObjectExtra (i, bfp, NULL);
24442   }
24443 
24444   i = CommandItem (s, "Trim Ns from Bioseqs", TrimNsFromNucs);
24445   SetObjectExtra (i, bfp, NULL);
24446   if (indexerVersion) {
24447     i = CommandItem (s, "Edit Sequence IDs", EditSeqIds);
24448     SetObjectExtra (i, bfp, NULL);
24449   }
24450 
24451 }
24452 
MakeSpecialClearMenu(MenU m,BaseFormPtr bfp)24453 static void MakeSpecialClearMenu (MenU m, BaseFormPtr bfp)
24454 {
24455   IteM  i;
24456   MenU  s;
24457 
24458   s = SubMenu (m, "Clear/ L");
24459 
24460   i = CommandItem (s, "Clear ORF Flag in CDSs", ClearOrfFlagInCDS);
24461   SetObjectExtra (i, bfp, NULL);
24462 
24463   SeparatorItem (s);
24464 
24465   i = CommandItem (s, "Clear GenBank Components", (ItmActnProc) EditGenbankElements);
24466   SetObjectExtra (i, bfp, NULL);
24467   if (indexerVersion)
24468   {
24469     i = CommandItem (s, "Clear Keywords", RemoveKeywordWithStringConstraint);
24470     SetObjectExtra (i, bfp, NULL);
24471 
24472     i = CommandItem (s, "Clear Nomenclature", RemoveNomenclature);
24473     SetObjectExtra (i, bfp, NULL);
24474   }
24475 
24476   SeparatorItem (s);
24477 
24478   i = CommandItem (s, "Clear Serial Numbers", StripSerials);
24479   SetObjectExtra (i, bfp, NULL);
24480 }
24481 
24482 
MakeSpecialGapSequencesMenu(MenU m,BaseFormPtr bfp)24483 static void MakeSpecialGapSequencesMenu (MenU m, BaseFormPtr bfp)
24484 {
24485   IteM  i;
24486   MenU  s;
24487   MenU  x;
24488 
24489   /* Gap Sequences Menu */
24490   s = SubMenu (m, "Gap Sequences/ G");
24491   x = SubMenu (s, "Raw Sequence to Delta");
24492   i = CommandItem (x, "By Ns",
24493                    RawSeqToDeltaSeqUnknownWithUnknownLengthGaps);
24494   SetObjectExtra (i, bfp, NULL);
24495   i = CommandItem (x, "By Location",
24496                    ConvertRawToDeltaWithGapLocations);
24497   SetObjectExtra (i, bfp, NULL);
24498   i = CommandItem (x, "By Assembly_Gap Features",
24499                    ConvertRawToDeltaWithGapFeatures);
24500   SetObjectExtra (i, bfp, NULL);
24501   i = CommandItem (x, "Merge Assembly_Gap Features",
24502                    ConvertAndMergeAssemblyGapFeatures);
24503   SetObjectExtra (i, bfp, NULL);
24504   i = CommandItem (s, "Delta Sequence to Raw", SegSeqToRawSeq);
24505   SetObjectExtra (i, bfp, NULL);
24506   i = CommandItem (s, "Far Delta to Near Delta", FarDeltaToNear);
24507   SetObjectExtra (i, bfp, NULL);
24508   SeparatorItem (s);
24509   x = SubMenu (s, "Convert Selected Gaps");
24510   i = CommandItem (x, "To Known Length", ConvertSelectedGapFeaturesToKnown);
24511   SetObjectExtra (i, bfp, NULL);
24512   i = CommandItem (x, "To Unknown Length", ConvertSelectedGapFeaturesToUnknown);
24513   SetObjectExtra (i, bfp, NULL);
24514   i = CommandItem (s, "Convert Known to Unknown (by Size)", ConvertGapFeaturesToUnknown);
24515   SetObjectExtra (i, bfp, NULL);
24516   i = CommandItem (s, "Edit Length of Selected Known Gaps", ChangeKnownGapLength);
24517   SetObjectExtra (i, bfp, NULL);
24518   i = CommandItem (s, "Expand Known Gaps to Include Flanking Ns", AddFlankingNsToKnownLengthGaps);
24519   SetObjectExtra (i, bfp, NULL);
24520   i = CommandItem (s, "Combine Adjacent Gaps", CombineAdjacentGaps);
24521   SetObjectExtra (i, bfp, NULL);
24522   SeparatorItem (s);
24523   i = CommandItem (s, "Adjust Features for Gaps", AdjustFeaturesForGaps);
24524   SetObjectExtra (i, bfp, NULL);
24525   i = CommandItem (s, "Trim coding regions for Ns", TrimCodingRegionsForNs);
24526   SetObjectExtra (i, bfp, NULL);
24527   i = CommandItem (s, "Convert CDS with Internal Gaps to Misc_feat", ConvertCodingRegionsWithInternalKnownGapToMiscFeat);
24528   SetObjectExtra (i, bfp, NULL);
24529   SeparatorItem (s);
24530   i = CommandItem (s, "Fix Delta SeqDataLen", FixDeltaSeqDataLen);
24531   SetObjectExtra (i, bfp, NULL);
24532   SeparatorItem (s);
24533   i = CommandItem (s, "Instantiate Gap Features from Delta Instructions", InstantiateGapFeatures);
24534   SetObjectExtra (i, bfp, NULL);
24535   i = CommandItem (s, "Convert Features with Gap Locations to Instantiated Gaps", RemoveFeaturesLikeGaps);
24536   SetObjectExtra (i, bfp, NULL);
24537   i = CommandItem (s, "Add Linkage to All Gaps", ApplyLinkageInfo);
24538   SetObjectExtra (i, bfp, NULL);
24539   SeparatorItem (s);
24540   i = CommandItem (s, "Flip Intervals Between Gaps", FlipSequenceIntervals);
24541   SetObjectExtra (i, bfp, NULL);
24542   SeparatorItem (s);
24543   i = CommandItem (s, "Remove Contigs from Scaffolds", RemoveContigFromScaffoldMenuItem);
24544   SetObjectExtra (i, bfp, NULL);
24545   SeparatorItem (s);
24546   i = CommandItem (s, "Replace Non-N Islands", RemoveNonNIslands);
24547   SetObjectExtra (i, bfp, NULL);
24548 }
24549 
MakeSpecialSelectMenu(MenU m,BaseFormPtr bfp)24550 static void MakeSpecialSelectMenu (MenU m, BaseFormPtr bfp)
24551 {
24552   IteM  i;
24553   MenU  s;
24554 
24555   s = SubMenu (m, "Select/ S");
24556   i = CommandItem (s, "Select Descriptors", SelectDescriptor);
24557   SetObjectExtra (i, bfp, NULL);
24558   i = CommandItem (s, "Select Features", SelectFeatures);
24559   SetObjectExtra (i, bfp, NULL);
24560   i = CommandItem (s, "Select Sequences", SelectBioseq);
24561   SetObjectExtra (i, bfp, NULL);
24562   i = CommandItem (s, "Select Publications", SelectPubs);
24563   SetObjectExtra (i, bfp, NULL);
24564   if (indexerVersion) {
24565     i = CommandItem (s, "Find Contig for Features", FindContig);
24566     SetObjectExtra (i, bfp, NULL);
24567   }
24568 }
24569 
24570 
MakeSpecialLinkMenu(MenU m,BaseFormPtr bfp)24571 static void MakeSpecialLinkMenu (MenU m, BaseFormPtr bfp)
24572 {
24573   IteM  i;
24574   MenU  s;
24575   MenU  x;
24576 
24577   s = SubMenu (m, "Link/ K");
24578   x = SubMenu (s, "Feature IDs");
24579   i = CommandItem (x, "Assign", AssignFeatIDs);
24580   SetObjectExtra (i, bfp, NULL);
24581   i = CommandItem (x, "Reassign", ReassignFeatIDs);
24582   SetObjectExtra (i, bfp, NULL);
24583   i = CommandItem (x, "Unique in Merged Set", UniqifyFeatIDs);
24584   SetObjectExtra (i, bfp, NULL);
24585   i = CommandItem (x, "Clear IDs and Links", ClearFeatIDsAndLinks);
24586   SetObjectExtra (i, bfp, NULL);
24587   SeparatorItem (s);
24588   x = SubMenu (s, "Create CDS-mRNA Links");
24589   i = CommandItem (x, "By Overlap", LinkByOverlap);
24590   SetObjectExtra (i, bfp, NULL);
24591   i = CommandItem (x, "By Product", LinkByProduct);
24592   SetObjectExtra (i, bfp, NULL);
24593   i = CommandItem (x, "By Label", LinkByLabel);
24594   SetObjectExtra (i, bfp, NULL);
24595   i = CommandItem (x, "By Label and Location", LinkByLabelAndLocation);
24596   SetObjectExtra (i, bfp, NULL);
24597   i = CommandItem (x, "With Tool", CDSmRNALinkTool);
24598   SetObjectExtra (i, bfp, NULL);
24599   i = CommandItem (x, "By Protein-ID Qualifier", MakeFeatIdXrefsFromProteinIdQualifiers);
24600   SetObjectExtra (i, bfp, NULL);
24601   i = CommandItem (x, "By Transcript-ID Qualifier", MakeFeatIdXrefsFromTranscriptIdQualifiers);
24602   SetObjectExtra (i, bfp, NULL);
24603   i = CommandItem (x, "From Unidirectional Xrefs", CompleteHalfFormedXrefPairs);
24604   SetObjectExtra (i, bfp, NULL);
24605 
24606   i = CommandItem (s, "Link Selected CDS and mRNA Pair", LinkSelected);
24607   SetObjectExtra (i, bfp, NULL);
24608   SeparatorItem (s);
24609   i = CommandItem (s, "Show Linked CDS or mRNA Feature", SelCDSmRNALink);
24610   SetObjectExtra (i, bfp, NULL);
24611 }
24612 
24613 
MakeSpecialDesktopMenu(MenU m,BaseFormPtr bfp)24614 static void MakeSpecialDesktopMenu (MenU m, BaseFormPtr bfp)
24615 {
24616   MenU s;
24617   IteM i;
24618 
24619   s = SubMenu (m, "Desktop");
24620   i = CommandItem (s, "Reorder by ID", ReorderSetByAccessionMenuItem);
24621   SetObjectExtra (i, bfp, NULL);
24622   i = CommandItem (s, "Repackage Parts", RepackagePartsMenuItem);
24623   SetObjectExtra (i, bfp, NULL);
24624   i = CommandItem (s, "Descriptor Propagate", DescriptorPropagateMenuItem);
24625   SetObjectExtra (i, bfp, NULL);
24626   i = CommandItem (s, "Segregate Sets", NewSegregateBioseqSetMenuItem);
24627   SetObjectExtra (i, bfp, NULL);
24628   i = CommandItem (s, "Segregate by Plant Groups", SegregateByPlantGroupItem);
24629   SetObjectExtra (i, bfp, NULL);
24630   i = CommandItem (s, "Segregate by Fungus Groups", SegregateByFungusGroupItem);
24631   SetObjectExtra (i, bfp, NULL);
24632   i = CommandItem (s, "Sequester Sets", SequesterSequencesMenuItem);
24633   SetObjectExtra (i, bfp, NULL);
24634   i = CommandItem (s, "Get Rid of Seg Gaps", GetRidOfSegGapMenuItem);
24635   SetObjectExtra (i, bfp, NULL);
24636   i = CommandItem (s, "Create SeqAlign", GenerateSeqAlignMenuItem);
24637   SetObjectExtra (i, bfp, NULL);
24638   i = CommandItem (s, "Update SeqAlign", UpdateSeqAlignMenuItem);
24639   SetObjectExtra (i, bfp, NULL);
24640 #if defined(OS_UNIX) || defined(OS_MSWIN)
24641   i = CommandItem (s, "Correct RNA strandedness (Use SMART)", CorrectRNAStrandednessMenuItem);
24642   SetObjectExtra (i, bfp, NULL);
24643 #endif
24644   i = CommandItem (s, "Bioseq RevComp By ID", BioseqRevCompByIDMenuItem);
24645   SetObjectExtra (i, bfp, NULL);
24646   i = CommandItem (s, "Add Sets", AddSetMenuItem);
24647   SetObjectExtra (i, bfp, NULL);
24648   i = CommandItem (s, "Remove Sets in Set", RemoveSetsInSetMenuItem);
24649   SetObjectExtra (i, bfp, NULL);
24650   i = CommandItem (s, "Remove Duplicate Nested Sets", RemoveDuplicateNestedSetsMenuItem);
24651   SetObjectExtra (i, bfp, NULL);
24652   i = CommandItem (s, "Group Explode", GroupExplodeMenuItem);
24653   SetObjectExtra (i, bfp, NULL);
24654 }
24655 
24656 
MakeSpecialStructuredCommentsMenu(MenU m,BaseFormPtr bfp)24657 static void MakeSpecialStructuredCommentsMenu (MenU m, BaseFormPtr bfp)
24658 {
24659   MenU s;
24660   MenU x;
24661   IteM i;
24662 
24663   s = SubMenu (m, "Structured Comments");
24664 
24665   i = CommandItem (s, "Apply Structured Comment Field", MacroApplyStructuredComment);
24666   SetObjectExtra (i, bfp, NULL);
24667 
24668   i = CommandItem (s, "Remove Structured Comment Field", MacroRemoveStructuredComment);
24669   SetObjectExtra (i, bfp, NULL);
24670 
24671   i = CommandItem (s, "Edit Structured Comment Field", MacroEditStructuredComment);
24672   SetObjectExtra (i, bfp, NULL);
24673 
24674   i = CommandItem (s, "Parse from Structured Comments", CreateTableReaderWindowWithStructuredComments);
24675   SetObjectExtra (i, bfp, NULL);
24676 
24677   x = SubMenu (s, "Edit Structured Comment Prefix-Suffix");
24678   i = CommandItem (x, "HIVData", AddStructuredCommentHivTag);
24679   SetObjectExtra (i, bfp, NULL);
24680   i = CommandItem (x, "FluData", AddStructuredCommentFluTag);
24681   SetObjectExtra (i, bfp, NULL);
24682   i = CommandItem (x, "MIGSData", AddStructuredCommentMIGSTag);
24683   SetObjectExtra (i, bfp, NULL);
24684   i = CommandItem (x, "MIMSData", AddStructuredCommentMIMSTag);
24685   SetObjectExtra (i, bfp, NULL);
24686   i = CommandItem (x, "MIENSData", AddStructuredCommentMIENSTag);
24687   SetObjectExtra (i, bfp, NULL);
24688   i = CommandItem (x, "MIMARKS:3.0", AddStructuredCommentMIMARKS30Tag);
24689   SetObjectExtra (i, bfp, NULL);
24690   i = CommandItem (x, "MIGS:3.0", AddStructuredCommentMIGS30Tag);
24691   SetObjectExtra (i, bfp, NULL);
24692   i = CommandItem (x, "MIMS:3.0", AddStructuredCommentMIMS30Tag);
24693   SetObjectExtra (i, bfp, NULL);
24694   i = CommandItem (x, "AssemblyData", AddStructuredCommentAssemblyDataTag);
24695   SetObjectExtra (i, bfp, NULL);
24696   i = CommandItem (x, "GenomeAssemblyData", AddStructuredCommentGenomeAssemblyDataTag);
24697   SetObjectExtra (i, bfp, NULL);
24698   i = CommandItem (x, "iBOL", AddStructuredCommentiBOLTag);
24699   SetObjectExtra (i, bfp, NULL);
24700 
24701   SeparatorItem (s);
24702 
24703   i = CommandItem (s, "Apply Keyword for Structured Comment", AddStructuredCommentKeywordsMenuItem);
24704   SetObjectExtra (i, bfp, NULL);
24705 
24706   if (indexerVersion) {
24707     i = CommandItem (s, "Clear Structured Comment Keywords", RemoveStructuredCommentKeywordsMenuItem);
24708     SetObjectExtra (i, bfp, NULL);
24709   }
24710 
24711   SeparatorItem (s);
24712 
24713   i = CommandItem (s, "Load Structured Comments from Table - indexer", CreateStructuredCommentsItem);
24714   SetObjectExtra (i, bfp, NULL);
24715 
24716   i = CommandItem (s, "Load Structured Comments from Table - public", SubmitterCreateStructuredComments);
24717   SetObjectExtra (i, bfp, NULL);
24718 
24719   i = CommandItem (s, "Export Structured Comment Table", ExportStructuredCommentTable);
24720   SetObjectExtra (i, bfp, NULL);
24721 
24722   SeparatorItem (s);
24723 
24724   i = CommandItem (s, "Parse Structured Comment into User Object", ParseCommentIntoStructuredObject);
24725   SetObjectExtra (i, bfp, NULL);
24726 
24727   i = CommandItem (s, "Convert Comments with Spaces to Structured Comments", ConvertCommentsWithSpacesToStructuredComments);
24728   SetObjectExtra (i, bfp, NULL);
24729 
24730   SeparatorItem (s);
24731 
24732   i = CommandItem (s, "Add Genome Assembly Structured Comment", ApplyGenomeAssemblyComment);
24733   SetObjectExtra (i, bfp, NULL);
24734   i = CommandItem (s, "Add Assembly Structured Comment", ApplyAssemblyComment);
24735   SetObjectExtra (i, bfp, NULL);
24736 
24737   SeparatorItem (s);
24738   i = CommandItem (s, "Reorder Structured Comment Fields", ReorderStructuredCommentFieldsItem);
24739   SetObjectExtra (i, bfp, NULL);
24740   SeparatorItem (s);
24741   i = CommandItem (s, "Remove All Structured Comments", RemoveStructCommMenuItem);
24742   SetObjectExtra (i, bfp, NULL);
24743   i = CommandItem (s, "Remove Duplicate Structured Comments", RemoveDuplicateStructuredComments);
24744   SetObjectExtra (i, bfp, NULL);
24745   i = CommandItem (s, "Remove Empty Structured Comments", RemoveEmptyStructuredCommentsItem);
24746   SetObjectExtra (i, bfp, NULL);
24747 }
24748 
24749 
SetupSpecialMenu(MenU m,BaseFormPtr bfp)24750 extern void SetupSpecialMenu (MenU m, BaseFormPtr bfp)
24751 
24752 {
24753   IteM  i;
24754   MenU  s;
24755   MenU  x;
24756   Char str[32];
24757 
24758   s = SubMenu (m, "Def Line/ D");
24759   x = SubMenu (s, "Automatic Def Line");
24760   i = CommandItem (x, "Default Options", AutoDef);
24761   SetObjectExtra (i, bfp, NULL);
24762   i = CommandItem (x, "No Modifiers", AutoDefWithoutModifiers);
24763   SetObjectExtra (i, bfp, NULL);
24764   i = CommandItem (x, "Select Options...", AutoDefWithOptions);
24765   SetObjectExtra (i, bfp, NULL);
24766   i = CommandItem (x, "Add Popset Titles", AddPopsetTitlesItem);
24767   SetObjectExtra (i, bfp, NULL);
24768   i = CommandItem(x, "Refresh Def Line with Previous Options", RefreshDefLine);
24769   SetObjectExtra(i, bfp, NULL);
24770   SeparatorItem(s);
24771   i = CommandItem (s, "Add Definition Line", ApplyTitle);
24772   SetObjectExtra (i, bfp, NULL);
24773   x = SubMenu (s, "Prefix Def Line With");
24774   i = CommandItem (x, "Organism", AddOrgNameToDefLines);
24775   SetObjectExtra (i, bfp, NULL);
24776   i = CommandItem (x, "Strain", AddStrainToDefLines);
24777   SetObjectExtra (i, bfp, NULL);
24778   i = CommandItem (x, "Clone", AddCloneToDefLines);
24779   SetObjectExtra (i, bfp, NULL);
24780   i = CommandItem (x, "Isolate", AddIsolateToDefLines);
24781   SetObjectExtra (i, bfp, NULL);
24782   i = CommandItem (x, "Haplotype", AddHaplotypeToDefLines);
24783   SetObjectExtra (i, bfp, NULL);
24784   i = CommandItem (x, "Cultivar", AddCultivarToDefLines);
24785   SetObjectExtra (i, bfp, NULL);
24786   i = CommandItem (x, "List", PrefixDefLines);
24787   SetObjectExtra (i, bfp, NULL);
24788   SeparatorItem (s);
24789   i = CommandItem (s, "Parse Text", ParseDefLineToSourceQual);
24790   SetObjectExtra (i, bfp, NULL);
24791 
24792   MakeSpecialOrganismMenu (m, bfp);
24793 
24794   MakeSpecialApplyMenu (m, bfp);
24795 
24796   MakeSpecialRemoveMenu (m, bfp);
24797 
24798   MakeSpecialConvertMenu (m, bfp);
24799 
24800   MakeSpecialEditMenu (m, bfp);
24801 
24802   MakeSpecialClearMenu (m, bfp);
24803 
24804   s = SubMenu (m, "CDS, Protein, and RNA");
24805   x = SubMenu (s, "Fix Product Name Capitalization");
24806   i = CommandItem (x, "Default", FixProductCapitalizationDefault);
24807   SetObjectExtra (i, bfp, NULL);
24808   i = CommandItem (x, "With Options", FixProductCapitalization);
24809   SetObjectExtra (i, bfp, NULL);
24810   SeparatorItem (s);
24811   x = SubMenu (s, "Retranslate Coding Regions");
24812   i = CommandItem (x, "Obey Stop Codon", RetranslateCdRegionsNoStop);
24813   SetObjectExtra (i, bfp, NULL);
24814   i = CommandItem (x, "Ignore Stop Codon", RetranslateCdRegionsDoStop);
24815   SetObjectExtra (i, bfp, NULL);
24816   i = CommandItem (x, "Ignore Stop Codon Except at End of Complete CDS", RetranslateCdRegionsNoStopExceptEndCompleteCDS);
24817   SetObjectExtra (i, bfp, NULL);
24818   i = CommandItem (x, "Choose Frame With No Stop Codon", RetranslateCdRegionsChooseFrameWithNoStop);
24819   SetObjectExtra (i, bfp, NULL);
24820 
24821   x = SubMenu (s, "Recompute Suggested Intervals");
24822   i = CommandItem (x, "And Update Genes", RecomputeSuggestFixGenes);
24823   SetObjectExtra (i, bfp, NULL);
24824   i = CommandItem (x, "Do Not Update Genes", RecomputeSuggest);
24825   SetObjectExtra (i, bfp, NULL);
24826   SeparatorItem (s);
24827   x = SubMenu (s, "Resynchronize Partials");
24828   i = CommandItem (x, "CDS", ResynchronizeCDSPartials);
24829   SetObjectExtra (i, bfp, NULL);
24830   i = CommandItem (x, "mRNA", ResynchronizeMRNAPartials);
24831   SetObjectExtra (i, bfp, NULL);
24832   i = CommandItem (x, "Peptide", ResynchronizePeptidePartials);
24833   SetObjectExtra (i, bfp, NULL);
24834   SeparatorItem (s);
24835   i = CommandItem (s, "Truncate Proteins and CDSs at Stops", TruncateProteins);
24836   SetObjectExtra (i, bfp, NULL);
24837   SeparatorItem (s);
24838   i = CommandItem (s, "Extend Proteins to Stops", ExtendProteins);
24839   SetObjectExtra (i, bfp, NULL);
24840 
24841   i = CommandItem (s, "Trim Protein Feature Lengths", TrimProtFeatLengths);
24842   SetObjectExtra (i, bfp, NULL);
24843   SeparatorItem (s);
24844   i = CommandItem (s, "Edit Coding Region Frame", ApplyCDSFrame);
24845   SetObjectExtra (i, bfp, NULL);
24846   x = SubMenu (s, "Adjust Features for Introns");
24847   i = CommandItem (x, "CDS", RemoveIntronLocationsFromCDS);
24848   SetObjectExtra (i, bfp, NULL);
24849   i = CommandItem (x, "rRNA", RemoveIntronLocationsFromrRNA);
24850   SetObjectExtra (i, bfp, NULL);
24851   i = CommandItem (x, "tRNA", RemoveIntronLocationsFromtRNA);
24852   SetObjectExtra (i, bfp, NULL);
24853   i = CommandItem (x, "mRNA", RemoveIntronLocationsFrommRNA);
24854   SetObjectExtra (i, bfp, NULL);
24855   x = SubMenu (s, "Adjust Last Exons for Stop Codons");
24856   i = CommandItem (x, "Do Not Change Last Exon Partial", FixLastExonLocNoPartial);
24857   SetObjectExtra (i, bfp, NULL);
24858   i = CommandItem (x, "Make Last Exon 3' Partial", FixLastExonLocMakePartial);
24859   SetObjectExtra (i, bfp, NULL);
24860   i = CommandItem (s, "Remove UTR locations from CDS location", RemoveUTRsFromCDSs);
24861   SetObjectExtra (i, bfp, NULL);
24862 
24863   x = SubMenu( s, "Adjust CDS for Consensus Splice Sites");
24864   i = CommandItem (x, "Strict", AdjustForConsensusSplice);
24865   SetObjectExtra (i, bfp, NULL);
24866   i = CommandItem (x, "Relaxed", AdjustForConsensusSpliceRelaxed);
24867   SetObjectExtra (i, bfp, NULL);
24868 
24869   SeparatorItem (s);
24870 
24871   i = CommandItem (s, "Convert CDS to mat_peptide", CombineMultipleCDS);
24872   SetObjectExtra (i, bfp, NULL);
24873   SeparatorItem (s);
24874   i = CommandItem (s, "Add Transl Excepts with Comment", AddTranslExceptWithComment);
24875   SetObjectExtra (i, bfp, NULL);
24876   SeparatorItem (s);
24877   i = CommandItem (s, "Mark Truncated Products by Protein Alignment", TruncateByProtAlign);
24878   SetObjectExtra (i, bfp, NULL);
24879 
24880   /* Authors and Publications */
24881   s = SubMenu (m, "Authors and Publications");
24882   i = CommandItem (s, "Edit Publications", EditPubs);
24883   SetObjectExtra (i, bfp, NULL);
24884   x = SubMenu (s, "Fix Capitalization");
24885   i = CommandItem (x, "All", FixAllPubCapitalization);
24886   SetObjectExtra (i, bfp, NULL);
24887   i = CommandItem (x, "Authors", FixAuthorCapitalization);
24888   SetObjectExtra (i, bfp, NULL);
24889   i = CommandItem (x, "Titles", FixTitleCapitalization);
24890   SetObjectExtra (i, bfp, NULL);
24891   i = CommandItem (x, "Affiliations", FixAffiliationCapitalization);
24892   SetObjectExtra (i, bfp, NULL);
24893   i = CommandItem (x, "Country", FixPubCountryCapitalization);
24894   SetObjectExtra (i, bfp, NULL);
24895   SeparatorItem (s);
24896   x = SubMenu (s, "Remove Publications");
24897   i = CommandItem (x, "Unpublished", RemoveUnpublishedPublications);
24898   SetObjectExtra (i, bfp, NULL);
24899   i = CommandItem (x, "Published", RemovePublishedPublications);
24900   SetObjectExtra (i, bfp, NULL);
24901   i = CommandItem (x, "Colliding", RemoveCollidingPublications);
24902   SetObjectExtra (i, bfp, NULL);
24903   i = CommandItem (x, "All", RemovePub);
24904   SetObjectExtra (i, bfp, NULL);
24905   i = CommandItem (s, "Remove Author Consortiums", RemovePubConsortiums);
24906   SetObjectExtra (i, bfp, NULL);
24907   SeparatorItem (s);
24908   i = CommandItem (s, "Reverse Author Order", FixNameOrder);
24909   SetObjectExtra (i, bfp, NULL);
24910   i = CommandItem (s, "Strip Author Suffixes", StripAuthorSuffix);
24911   SetObjectExtra (i, bfp, NULL);
24912   i = CommandItem (s, "Truncate Author Middle Initials", TruncateAuthorMiddle);
24913   SetObjectExtra (i, bfp, NULL);
24914   x = SubMenu (s, "Convert Author to Consortium");
24915   i = CommandItem (x, "All", ChangeAllAuthorNameToConsortium);
24916   SetObjectExtra (i, bfp, NULL);
24917   i = CommandItem (x, "With String Constraint", ChangeAuthorNameToConsortiumWithConstraint);
24918   SetObjectExtra (i, bfp, NULL);
24919   i = CommandItem (x, "Where Last Name Contains 'Consortium'", ChangeAuthorNameWithConsortiumToConsortium);
24920   SetObjectExtra (i, bfp, NULL);
24921   SeparatorItem (s);
24922   i = CommandItem (s, "Add Cit-sub for update", AddCitSubForUpdate);
24923   SetObjectExtra (i, bfp, NULL);
24924   i = CommandItem (s, "Fix USA and States", AbbreviateCitSubAffilStates);
24925   SetObjectExtra (i, bfp, NULL);
24926   SeparatorItem (s);
24927   i = CommandItem (s, "Global PubMedId Lookup", GLobalArticleLookupMenuItem);
24928   SetObjectExtra (i, bfp, NULL);
24929 
24930   MakeSpecialGapSequencesMenu (m, bfp);
24931 
24932   s = SubMenu (m, "Make Features and Fuse");
24933   i = CommandItem (s, "Gene Features from Xrefs", XrefToGene);
24934   SetObjectExtra (i, bfp, NULL);
24935   i = CommandItem (s, "Gene Xrefs from Features", GeneToXref);
24936   SetObjectExtra (i, bfp, NULL);
24937   i  = CommandItem (s, "Gene Features From Other Features", FeatureToGene);
24938   SetObjectExtra (i, bfp, NULL);
24939   SeparatorItem (s);
24940 
24941   i = CommandItem (s, "CDS Features from Gene, mRNA, or exon", FeatureToCds);
24942   SetObjectExtra (i, bfp, NULL);
24943   i = CommandItem (s, "Make AltSplice CDSs for mRNAs", MakeCDSmRNAPairs);
24944   SetObjectExtra (i, bfp, NULL);
24945   i = CommandItem (s, "mRNA Features from Gene, CDS, or exon", FeatureTomRNA);
24946   SetObjectExtra (i, bfp, NULL);
24947   x = SubMenu (s, "Exon features from");
24948   i = CommandItem (x, "CDS Intervals", MakeExonsFromCDSIntervals);
24949   SetObjectExtra (i, bfp, NULL);
24950   i = CommandItem (x, "mRNA Intervals", MakeExonsFromMRNAIntervals);
24951   SetObjectExtra (i, bfp, NULL);
24952   SeparatorItem (s);
24953 
24954   i = CommandItem (s, "Fuse Features", FuseFeature);
24955   SetObjectExtra (i, bfp, NULL);
24956   if (indexerVersion) {
24957     i = CommandItem (s, "Fuse Joins in Locations", FuseSlpJoins);
24958     SetObjectExtra (i, bfp, NULL);
24959   }
24960   SeparatorItem (s);
24961   i = CommandItem (s, "Combine Selected Genes into Pseudogene", CombineToCreatePseudoGene);
24962   SetObjectExtra (i, bfp, NULL);
24963 
24964   SeparatorItem (s);
24965   i = CommandItem (s, "Explode RNA Features", ExplodeRNA);
24966   SetObjectExtra (i, bfp, NULL);
24967 
24968   SeparatorItem (s);
24969   i = CommandItem (s, "Process FASTA Proteins", ParseInMoreProteins);
24970   SetObjectExtra (i, bfp, NULL);
24971 
24972   s = SubMenu (m, "Normalize, Map, Package");
24973   i = CommandItem (s, "Renormalize Nuc-Prot Sets", RenormalizeNucProtSetsMenuItem);
24974   SetObjectExtra (i, bfp, NULL);
24975   SeparatorItem (s);
24976 
24977   i = CommandItem (s, "Package Features on Parts", PackageOnParts);
24978   SetObjectExtra (i, bfp, NULL);
24979   i = CommandItem (s, "Package Proteins on Nucleotides", PackageOnNucs);
24980   SetObjectExtra (i, bfp, NULL);
24981   SeparatorItem (s);
24982 
24983   x = SubMenu (s, "Map Feature Intervals to Parts");
24984   i = CommandItem (x, "Joined Location", MergeToPartsJoin);
24985   SetObjectExtra (i, bfp, NULL);
24986   i = CommandItem (x, "Ordered Location", MergeToPartsOrdered);
24987   SetObjectExtra (i, bfp, NULL);
24988   i = CommandItem (s, "Map Intervals to Segmented Sequence", MergeToSegSeq);
24989   SetObjectExtra (i, bfp, NULL);
24990   i = CommandItem (s, "Map Features to Protein Sequences", MapFeaturesToProteinSequence);
24991   SetObjectExtra (i, bfp, NULL);
24992   SeparatorItem (s);
24993 
24994   if (indexerVersion) {
24995     i = CommandItem (s, "Connect CDS to Closest Protein", ReconnectCDSProduct);
24996     SetObjectExtra (i, bfp, NULL);
24997     SeparatorItem (s);
24998   }
24999 
25000   i = CommandItem (s, "Map Selected Features to Upstream Gene", MapFeatToUpstreamGene);
25001   SetObjectExtra (i, bfp, NULL);
25002   i = CommandItem (s, "Map Selected Features to Downstream Gene", MapFeatToDownstreamGene);
25003   SetObjectExtra (i, bfp, NULL);
25004   SeparatorItem (s);
25005 
25006   i = CommandItem (s, "Suppress Genes On Features", SuppressGenesOnFeatures);
25007   SetObjectExtra (i, bfp, NULL);
25008   x = SubMenu (s, "CDSGeneRange Error");
25009   i = CommandItem (x, "Suppress", SuppressCDSGeneRangeError);
25010   SetObjectExtra (i, bfp, NULL);
25011   i = CommandItem (x, "Restore", RestoreCDSGeneRangeError);
25012   SetObjectExtra (i, bfp, NULL);
25013 
25014   i = CommandItem (s, "Suppress genes inside mobile elements", SuppressGenesOnFeaturesInsideMobileElements);
25015   SetObjectExtra (i, bfp, NULL);
25016 
25017   s = SubMenu (m, "Projects/ J");
25018   MakeSpecialProjectsMenu (s, bfp);
25019 
25020   MakeSpecialStructuredCommentsMenu (m, bfp);
25021 
25022   s = SubMenu (m, "Cleanup and Fixup");
25023   i = CommandItem (s, "Clean Up Record", ForceCleanup);
25024   SetObjectExtra (i, bfp, NULL);
25025   SeparatorItem (s);
25026   i = CommandItem (s, "Force Locus Fixup", ForceLocusFixup);
25027   SetObjectExtra (i, bfp, NULL);
25028   SeparatorItem (s);
25029   i = CommandItem (s, "Update Replaced EC_numbers", UpdateECnumbers);
25030   SetObjectExtra (i, bfp, NULL);
25031   i = CommandItem (s, "Parse GO Terms from User Fields", ParseGoTermsFromUserFieldsItem);
25032   SetObjectExtra (i, bfp, NULL);
25033   SeparatorItem (s);
25034   i = CommandItem (s, "NC_Cleanup", DoNCCleanup);
25035   SetObjectExtra (i, bfp, NULL);
25036   SeparatorItem (s);
25037   i = CommandItem (s, "PT_Cleanup", DoPTCleanup);
25038   SetObjectExtra (i, bfp, NULL);
25039   if (indexerVersion) {
25040     SeparatorItem (s);
25041     i = CommandItem (s, "SeriousSeqEntryCleanup", DoSSECleanup);
25042     SetObjectExtra (i, bfp, NULL);
25043     SeparatorItem (s);
25044     i = CommandItem (s, "Demote GenProdSet To NucProtSet", GPStoNPS);
25045     SetObjectExtra (i, bfp, NULL);
25046   }
25047 
25048   MakeSpecialLocusTagMenu (m, bfp);
25049 
25050   s = SubMenu (m, "Display/ I");
25051   i = CommandItem (s, "View Sorted Protein FASTA", ViewSortedProteinMenuItem);
25052   SetObjectExtra (i, bfp, NULL);
25053   if (extraServices) {
25054     i = CommandItem (s, "Make ToolBar Window/ T", MakeToolBarWindow);
25055     SetObjectExtra (i, bfp, NULL);
25056     i = CommandItem (s, "Make WGS Toolbar/ W", MakeWGSToolBar);
25057     SetObjectExtra (i, bfp, NULL);
25058     if (GetAppParam (customtoolbarini, "MAIN", "NUM_TABS", NULL, str, sizeof (str))) {
25059       i = CommandItem (s, "Custom Toolbar", MakeCustomToolbar);
25060       SetObjectExtra (i, bfp, NULL);
25061     }
25062   }
25063   i = CommandItem (s, "VecScreenTool", VecScreenTool);
25064   SetObjectExtra (i, bfp, NULL);
25065   i = CommandItem (s, "On-Caller Tool", ShowOnCallerTool);
25066   SetObjectExtra (i, bfp, NULL);
25067   i = CommandItem (s, "Print Test List", PrintDiscrepancyTestListMenuItem);
25068   SetObjectExtra (i, bfp, NULL);
25069   i = CommandItem (s, "Show Custom Toolbar Button List", ListCustomToolbarFunctions);
25070   SetObjectExtra (i, bfp, NULL);
25071   i = CommandItem (s, "Find Frame Shifts", FrameShiftFinder);
25072   SetObjectExtra (i, bfp, NULL);
25073   i = CommandItem (s, "Find Frame Shifts Clipboard", FrameShiftFinderClipboard);
25074   SetObjectExtra (i, bfp, NULL);
25075 
25076   MakeSpecialDesktopMenu (m, bfp);
25077 
25078   MakeSpecialLinkMenu (m, bfp);
25079 
25080   MakeSpecialSelectMenu (m, bfp);
25081 
25082   SeparatorItem (m);
25083   s = SubMenu (m, "Sort Unique Count/ U");
25084   x = SubMenu (s, "By Group");
25085   i = CommandItem (x, "Without Sequence", SUCBNoSequenceProc);
25086   SetObjectExtra (i, bfp, NULL);
25087   i = CommandItem (x, "With Sequence", SUCBProc);
25088   SetObjectExtra (i, bfp, NULL);
25089   i = CommandItem (s, "Original (by position)", SUCProc);
25090   SetObjectExtra (i, bfp, NULL);
25091   i = CommandItem (s, "Resorted (by frequency)/ N", SUCRProc);
25092   SetObjectExtra (i, bfp, NULL);
25093   x = SubMenu (s, "Clickable");
25094   i = CommandItem (x, "Without Sequence", SUCClickableNoSequenceProc);
25095   SetObjectExtra (i, bfp, NULL);
25096   i = CommandItem (x, "With Sequence", SUCClickableProc);
25097   SetObjectExtra (i, bfp, NULL);
25098 
25099   if (indexerVersion) {
25100     SeparatorItem (m);
25101     s = SubMenu (m, "Export Alignment");
25102     i = CommandItem (s, "Interleave", ExportAlignmentInterleave);
25103     SetObjectExtra (i, bfp, NULL);
25104     i = CommandItem (s, "Contiguous", ExportAlignmentContiguous);
25105     SetObjectExtra (i, bfp, NULL);
25106 
25107     SeparatorItem (m);
25108     s = SubMenu (m, "Test");
25109     i = CommandItem (s, "Test New Parse", TestNewParse);
25110     SetObjectExtra (i, bfp, NULL);
25111 
25112     i = CommandItem (s, "Test Product Table Export", TestProductTableExport);
25113     SetObjectExtra (i, bfp, NULL);
25114     i = CommandItem (s, "Test Product Table Update", TestProductTableUpdate);
25115     SetObjectExtra (i, bfp, NULL);
25116 
25117 #if 0
25118     i = CommandItem (s, "Test Segregate By List", TestSegregateByList);
25119     SetObjectExtra (i, bfp, NULL);
25120 #endif
25121 #if 0
25122     SeparatorItem (m);
25123     s = SubMenu (m, "Test Taxon3 Server");
25124     i = CommandItem (s, "9606", TestTax3A);
25125     i = CommandItem (s, "E. coli", TestTax3B);
25126     SetObjectExtra (i, bfp, NULL);
25127 #endif
25128 
25129 #if 0
25130     SeparatorItem (m);
25131     i = CommandItem (m, "Add All Dbxrefs", AddAllDbxrefsMenuItem);
25132     SetObjectExtra (i, bfp, NULL);
25133 #endif
25134 
25135   }
25136   SeparatorItem (m);
25137   i = CommandItem (m, "Mega Report", ShowMegaReport);
25138   SetObjectExtra (i, bfp, NULL);
25139   i = CommandItem (m, "Discrepancy Report", ShowDiscrepancyReport);
25140   SetObjectExtra (i, bfp, NULL);
25141   SeparatorItem (m);
25142   i = CommandItem (m, "Macro Editor", LaunchMacroEditorMenuItem);
25143   SetObjectExtra (i, bfp, NULL);
25144   i = CommandItem (m, "Macro Template Editor", LaunchMacroTemplateEditor);
25145   SetObjectExtra (i, bfp, NULL);
25146 #if 1
25147   i = CommandItem (m, "Suspect Product Rule Editor", LaunchSuspectProductRuleEditor);
25148   SetObjectExtra (i, bfp, NULL);
25149 #endif
25150   i = CommandItem (m, "AutoFix", RunAutoFixScriptMenuItem);
25151   SetObjectExtra (i, bfp, NULL);
25152   i = CommandItem (m, "AutoFix Window", RunAutoFixWindowMenuItem);
25153   SetObjectExtra (i, bfp, NULL);
25154 
25155 #ifdef TEST_VALIDAPI
25156   i = CommandItem (m, "Rules Editor", LaunchCommentRulesEditor);
25157   SetObjectExtra (i, bfp, NULL);
25158 #endif
25159 
25160   /*
25161   SeparatorItem (m);
25162   i = CommandItem (m, "Modernize PCR Primers", ModernizePCRs);
25163   SetObjectExtra (i, bfp, NULL);
25164   i = CommandItem (m, "Modernize Misc RNAs", ModernizeRNAs);
25165   SetObjectExtra (i, bfp, NULL);
25166   i = CommandItem (m, "Modernize Gene Nomenclature", ModernizeGenes);
25167   SetObjectExtra (i, bfp, NULL);
25168   */
25169 
25170 
25171 /*#ifdef INTERNAL_NCBI_SEQUIN*/
25172 /*#ifdef NEW_TAXON_SERVICE*/
25173 /*
25174   SeparatorItem (m);
25175   i = CommandItem (m, "Prepare TaxList", PrepareTaxListProc);
25176 */
25177 /*#endif*/
25178 /*#endif*/
25179 }
25180 
SetupBatchApplyMenu(MenU s,BaseFormPtr bfp)25181 extern void SetupBatchApplyMenu (MenU s, BaseFormPtr bfp)
25182 
25183 {
25184   IteM  i;
25185 
25186   i = CommandItem (s, "Add CDS", ApplyCDS);
25187   SetObjectExtra (i, bfp, NULL);
25188   i = CommandItem (s, "Add RNA", ApplyRRNA);
25189   SetObjectExtra (i, bfp, NULL);
25190   i = CommandItem (s, "Add other Feature", ApplyImpFeat);
25191   SetObjectExtra (i, bfp, NULL);
25192   i = CommandItem (s, "Add Qualifier", PublicApplyGBQual);
25193   SetObjectExtra (i, bfp, NULL);
25194   SeparatorItem (s);
25195   i = CommandItem (s, "Add Source Qual", PublicApplySourceQual);
25196   SetObjectExtra (i, bfp, NULL);
25197   i = CommandItem (s, "Add CDS-Gene-Prot-mRNA Qual", PublicApplyCDSGeneProt);
25198   SetObjectExtra (i, bfp, NULL);
25199   i = CommandItem (s, "Add RNA Qual", PublicApplyRNAQual);
25200   SetObjectExtra (i, bfp, NULL);
25201 }
25202 
SetupBatchEditMenu(MenU s,BaseFormPtr bfp)25203 extern void SetupBatchEditMenu (MenU s, BaseFormPtr bfp)
25204 
25205 {
25206   IteM  i;
25207 
25208   i = CommandItem (s, "Edit Qualifiers", PublicEditGBQual);
25209   SetObjectExtra (i, bfp, NULL);
25210   i = CommandItem (s, "Edit Source Qual", PublicEditSourceQual);
25211   SetObjectExtra (i, bfp, NULL);
25212   i = CommandItem (s, "Edit CDS-Gene-Prot Qual", PublicEditCDSGeneProt);
25213   SetObjectExtra (i, bfp, NULL);
25214   i = CommandItem (s, "Edit RNA Qual", PublicEditRNAQual);
25215   SetObjectExtra (i, bfp, NULL);
25216 }
25217 
25218