~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to sequin/sequin8.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   2/3/98
31
31
*
32
 
* $Revision: 6.147 $
 
32
* $Revision: 6.271 $
33
33
*
34
34
* File Description: 
35
35
*
58
58
#include <spidey.h>
59
59
#include <blast.h>
60
60
 
 
61
#define DEFLINE_MAX_LEN          380
 
62
#define TEXT_MAX_LEN             64
 
63
#define DEFLINE_MAX_GENENAME_LEN 64
 
64
#define ALL_FEATURES             255
 
65
 
61
66
typedef struct evidenceformdata {
62
67
  FEATURE_FORM_BLOCK
63
68
 
67
72
  Uint2          subtype;
68
73
  PopuP          evdence;
69
74
  Uint2          exp_ev;
70
 
  ObjMgrPtr      omp;
71
 
  ObjMgrTypePtr  omtp;
72
75
  ValNodePtr     head;
73
76
  Boolean        stringfound;
74
77
  Char           findStr [128];
75
 
} EvidenceFormData, PNTR EvidenceFormPtr;
76
 
 
77
 
static void LIBCALLBACK AsnWriteEvidenceCallBack (AsnExpOptStructPtr pAEOS)
78
 
 
79
 
{
80
 
  EvidenceFormPtr  efp;
81
 
  CharPtr          pchFind;
82
 
  CharPtr          pchSource;
83
 
 
84
 
  efp = (EvidenceFormPtr) pAEOS->data;
85
 
  if (ISA_STRINGTYPE (AsnFindBaseIsa (pAEOS->atp))) {
86
 
        pchSource = (CharPtr) pAEOS->dvp->ptrvalue;
87
 
        pchFind = efp->findStr;
88
 
        if (StringSearch (pchSource, pchFind) != NULL) {
89
 
          efp->stringfound = TRUE;
90
 
        }
91
 
  }
92
 
}
93
 
 
94
 
static Boolean EvidenceHasSubstring (ObjMgrTypePtr omtp, AsnIoPtr aip, Pointer ptr, EvidenceFormPtr efp)
95
 
 
96
 
{
97
 
  efp->stringfound = FALSE;
98
 
  (omtp->asnwrite) (ptr, aip, NULL);
99
 
  return efp->stringfound;
100
 
}
101
 
 
102
 
static void EvidenceCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
103
 
 
104
 
{
105
 
  AsnExpOptPtr     aeop;
106
 
  AsnIoPtr         aip;
107
 
  BioseqPtr        bsp;
108
 
  BioseqSetPtr     bssp;
109
 
  EvidenceFormPtr  efp;
110
 
  Boolean          notext;
111
 
  ObjMgrTypePtr    omtp;
112
 
  SeqAnnotPtr      sap;
113
 
  SeqFeatPtr       sfp;
114
 
  Uint2            subtype;
115
 
 
116
 
  if (mydata == NULL) return;
117
 
  if (sep == NULL || sep->data.ptrvalue == NULL) return;
118
 
  efp = (EvidenceFormPtr) mydata;
119
 
  if (efp == NULL) return;
120
 
  omtp = efp->omtp;
121
 
  if (omtp == NULL || omtp->subtypefunc == NULL) return;
122
 
  if (IS_Bioseq (sep)) {
123
 
    bsp = (BioseqPtr) sep->data.ptrvalue;
124
 
    sap = bsp->annot;
125
 
  } else if (IS_Bioseq_set (sep)) {
126
 
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
127
 
    sap = bssp->annot;
128
 
  } else return;
129
 
  GetTitle (efp->findthis, efp->findStr, sizeof (efp->findStr) - 1);
130
 
  notext = StringHasNoText (efp->findStr);
131
 
  aip = AsnIoNullOpen ();
132
 
  aeop = AsnExpOptNew (aip, NULL, NULL, AsnWriteEvidenceCallBack);
133
 
  if (aeop != NULL) {
134
 
    aeop->user_data = (Pointer) efp;
135
 
  }
136
 
  while (sap != NULL) {
137
 
    if (sap->type == 1) {
138
 
      sfp = (SeqFeatPtr) sap->data;
139
 
      while (sfp != NULL) {
140
 
        subtype = (*(omtp->subtypefunc)) ((Pointer) sfp);
141
 
        if (efp->subtype == 0 || subtype == efp->subtype ||
 
78
  ButtoN         case_insensitive;
 
79
  ButtoN         when_string_not_present;
 
80
} EvidenceFormData, PNTR 
 
81
 
 
82
EvidenceFormPtr;
 
83
 
 
84
typedef struct codebreakformdata {
 
85
  FEATURE_FORM_BLOCK
 
86
  PopuP  aminoAcidPopup;
 
87
  Char   currentCodonStr [4];
 
88
  TexT   codonText;
 
89
  ButtoN acceptButton;
 
90
} CodeBreakFormData, PNTR CodeBreakFormPtr;
 
91
 
 
92
static Boolean IsRealImpFeat (Uint2 subtype)
 
93
 
 
94
{
 
95
  if (subtype >= FEATDEF_allele && subtype <= FEATDEF_site_ref) return TRUE;
 
96
  if (subtype == FEATDEF_oriT) return TRUE;
 
97
  return FALSE;
 
98
}
 
99
 
 
100
static void DoEvidenceFeatureProc (SeqFeatPtr sfp, Pointer userdata)
 
101
{
 
102
  EvidenceFormPtr efp;
 
103
  
 
104
  if (sfp == NULL || userdata == NULL) return;
 
105
  efp = (EvidenceFormPtr) userdata;
 
106
 
 
107
  if (efp->subtype == 0 || sfp->idx.subtype == efp->subtype ||
142
108
           (efp->subtype == FEATDEF_IMP &&
143
 
            subtype >= FEATDEF_allele && subtype <= FEATDEF_site_ref)) {
144
 
          if (notext || EvidenceHasSubstring (omtp, aip, (Pointer) sfp, efp)) {
145
 
            sfp->exp_ev = (Uint1) efp->exp_ev;
146
 
          }
147
 
        }
148
 
        sfp = sfp->next;
149
 
      }
150
 
    }
151
 
    sap = sap->next;
 
109
            IsRealImpFeat (sfp->idx.subtype)))
 
110
  {
 
111
    sfp->exp_ev = (Uint1) efp->exp_ev;
152
112
  }
153
 
  AsnIoClose (aip);
154
113
}
155
114
 
156
115
static void DoEvidence (ButtoN b)
157
116
 
158
117
{
159
 
  EvidenceFormPtr  efp;
160
 
  SeqEntryPtr      sep;
161
 
  Uint2            subtype;
162
 
  Int2             val;
163
 
  ValNodePtr       vnp;
 
118
  EvidenceFormPtr      efp;
 
119
  SeqEntryPtr          sep;
 
120
  Uint2                subtype;
 
121
  Int2                 val;
 
122
  ValNodePtr           vnp;
 
123
  FeaturesWithTextData fd;
164
124
 
165
125
  efp = GetObjectExtra (b);
166
126
  if (efp == NULL) return;
183
143
  if (vnp != NULL) {
184
144
    subtype = vnp->choice;
185
145
  }
186
 
  efp->omp = ObjMgrGet ();
187
 
  efp->omtp = NULL;
188
 
  if (efp->omp != NULL) {
189
 
    efp->omtp = ObjMgrTypeFind (efp->omp, efp->itemtype, NULL, NULL);
190
 
  }
191
146
  efp->subtype = subtype;
192
147
  efp->exp_ev = GetValue (efp->evdence) - 1;
193
 
  if (efp->itemtype != 0 && efp->omtp != NULL) {
194
 
    SeqEntryExplore (sep, (Pointer) efp, EvidenceCallback);
195
 
  }
 
148
  
 
149
  GetTitle (efp->findthis, efp->findStr, sizeof (efp->findStr) - 1);
 
150
  fd.search_text = efp->findStr;
 
151
  fd.no_text = StringHasNoText (efp->findStr);
 
152
  fd.seqFeatChoice = 0;
 
153
  fd.featDefChoice = 0;
 
154
  fd.case_insensitive = GetStatus (efp->case_insensitive);
 
155
  fd.act_when_string_not_present = GetStatus (efp->when_string_not_present);
 
156
  fd.callback = DoEvidenceFeatureProc;
 
157
  fd.userdata = efp;
 
158
 
 
159
  OperateOnSeqEntryFeaturesWithText (sep, &fd);
 
160
 
196
161
  ArrowCursor ();
197
162
  Update ();
198
163
  ObjMgrSetDirtyFlag (efp->input_entityID, TRUE);
231
196
  BaseFormPtr        bfp;
232
197
  ButtoN             b;
233
198
  GrouP              c;
234
 
  FeatDefPtr         curr;
235
199
  EvidenceFormPtr    efp;
236
200
  GrouP              g;
237
201
  GrouP              h;
238
202
  ValNodePtr         head;
239
203
  GrouP              k;
240
 
  Uint1              key;
241
 
  CharPtr            label = NULL;
242
204
  Int2               listHeight;
243
205
  GrouP              q;
244
206
  SeqEntryPtr        sep;
245
207
  StdEditorProcsPtr  sepp;
246
 
  Uint2              subtype;
247
208
  ValNodePtr         vnp;
248
209
  WindoW             w;
249
210
 
283
244
    listHeight = 8;
284
245
  }
285
246
  efp->objlist = SingleList (g, 16, listHeight, NULL);
286
 
  head = ValNodeNew (NULL);
287
 
  if (head != NULL) {
288
 
    head->choice = 0;
289
 
    head->data.ptrvalue = StringSave ("[ALL FEATURES]");
290
 
  }
291
 
  curr = FeatDefFindNext (NULL, &key, &label, FEATDEF_ANY, TRUE);
292
 
  while (curr != NULL) {
293
 
    if (key != FEATDEF_BAD) {
294
 
      subtype = curr->featdef_key;
295
 
      if (subtype != FEATDEF_misc_RNA &&
296
 
          subtype != FEATDEF_precursor_RNA &&
297
 
          subtype != FEATDEF_mat_peptide &&
298
 
          subtype != FEATDEF_sig_peptide &&
299
 
          subtype != FEATDEF_transit_peptide) {
300
 
        vnp = ValNodeNew (head);
301
 
        /* if (head == NULL) {
302
 
          head = vnp;
303
 
        } */
304
 
        if (vnp != NULL) {
305
 
          vnp->choice = subtype;
306
 
          vnp->data.ptrvalue = StringSave (curr->typelabel);
307
 
        }
308
 
      }
309
 
    }
310
 
    curr = FeatDefFindNext (curr, &key, &label, FEATDEF_ANY, TRUE);
311
 
  }
312
 
  if (head != NULL) {
313
 
    head = SortValNode (head, SortByVnpChoice);
 
247
  head = BuildFeatureValNodeList (TRUE, "[ALL FEATURES]", 0, FALSE, TRUE);
 
248
  if (head != NULL) {
314
249
    for (vnp = head; vnp != NULL; vnp = vnp->next) {
315
250
      ListItem (efp->objlist, (CharPtr) vnp->data.ptrvalue);
316
251
    }
325
260
  PopupItem (efp->evdence, "Non-Experimental");
326
261
  SetValue (efp->evdence, 1);
327
262
 
328
 
  k = HiddenGroup (h, 0, 2, NULL);
 
263
  k = HiddenGroup (h, 0, 4, NULL);
329
264
  StaticPrompt (k, "Optional string constraint", 0, dialogTextHeight, programFont, 'c');
330
265
  efp->findthis = DialogText (k, "", 14, NULL);
 
266
  efp->case_insensitive = CheckBox (k, "Case insensitive", NULL);
 
267
  efp->when_string_not_present = CheckBox (k, "When String is Not Present", NULL);
331
268
 
332
269
  c = HiddenGroup (h, 4, 0, NULL);
333
 
  b = PushButton (c, "Accept", DoEvidence);
 
270
  b = DefaultButton (c, "Accept", DoEvidence);
334
271
  SetObjectExtra (b, efp, NULL);
335
272
  PushButton (c, "Cancel", StdCancelButtonProc);
336
273
 
349
286
  Uint2          subtype;
350
287
  GrouP          xception;
351
288
  TexT           xceptText;
 
289
  PopuP          xceptTextPopup;
352
290
  ButtoN         rescueExpl;
353
291
  Boolean        excpt;
354
292
  CharPtr        except_text;
355
293
  Boolean        rescue;
356
 
  ObjMgrPtr      omp;
357
 
  ObjMgrTypePtr  omtp;
358
294
  ValNodePtr     head;
359
295
  Boolean        stringfound;
360
296
  Char           findStr [128];
 
297
  GrouP          prodgrp;
 
298
  Int2           prodval;
 
299
  ButtoN         case_insensitive;
 
300
  ButtoN         when_string_not_present;
361
301
} ExceptionFormData, PNTR ExceptionFormPtr;
362
302
 
363
 
static void LIBCALLBACK AsnWriteExceptionCallBack (AsnExpOptStructPtr pAEOS)
364
 
 
365
 
{
366
 
  ExceptionFormPtr  efp;
367
 
  CharPtr          pchFind;
368
 
  CharPtr          pchSource;
369
 
 
370
 
  efp = (ExceptionFormPtr) pAEOS->data;
371
 
  if (ISA_STRINGTYPE (AsnFindBaseIsa (pAEOS->atp))) {
372
 
        pchSource = (CharPtr) pAEOS->dvp->ptrvalue;
373
 
        pchFind = efp->findStr;
374
 
        if (StringSearch (pchSource, pchFind) != NULL) {
375
 
          efp->stringfound = TRUE;
376
 
        }
377
 
  }
378
 
}
379
 
 
380
 
static Boolean ExceptionHasSubstring (ObjMgrTypePtr omtp, AsnIoPtr aip, Pointer ptr, ExceptionFormPtr efp)
381
 
 
382
 
{
383
 
  efp->stringfound = FALSE;
384
 
  (omtp->asnwrite) (ptr, aip, NULL);
385
 
  return efp->stringfound;
386
 
}
387
 
 
388
 
static void ExceptionCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
389
 
 
390
 
{
391
 
  AsnExpOptPtr      aeop;
392
 
  AsnIoPtr          aip;
393
 
  BioseqPtr         bsp;
394
 
  BioseqSetPtr      bssp;
395
 
  ExceptionFormPtr  efp;
396
 
  Boolean           notext;
397
 
  ObjMgrTypePtr     omtp;
398
 
  SeqAnnotPtr       sap;
399
 
  SeqFeatPtr        sfp;
400
 
  CharPtr           str;
401
 
  Uint2             subtype;
402
 
 
403
 
  if (mydata == NULL) return;
404
 
  if (sep == NULL || sep->data.ptrvalue == NULL) return;
405
 
  efp = (ExceptionFormPtr) mydata;
406
 
  if (efp == NULL) return;
407
 
  omtp = efp->omtp;
408
 
  if (omtp == NULL || omtp->subtypefunc == NULL) return;
409
 
  if (IS_Bioseq (sep)) {
410
 
    bsp = (BioseqPtr) sep->data.ptrvalue;
411
 
    sap = bsp->annot;
412
 
  } else if (IS_Bioseq_set (sep)) {
413
 
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
414
 
    sap = bssp->annot;
415
 
  } else return;
416
 
  GetTitle (efp->findthis, efp->findStr, sizeof (efp->findStr) - 1);
417
 
  notext = StringHasNoText (efp->findStr);
418
 
  aip = AsnIoNullOpen ();
419
 
  aeop = AsnExpOptNew (aip, NULL, NULL, AsnWriteExceptionCallBack);
420
 
  if (aeop != NULL) {
421
 
    aeop->user_data = (Pointer) efp;
422
 
  }
423
 
  while (sap != NULL) {
424
 
    if (sap->type == 1) {
425
 
      sfp = (SeqFeatPtr) sap->data;
426
 
      while (sfp != NULL) {
427
 
        subtype = (*(omtp->subtypefunc)) ((Pointer) sfp);
428
 
        if (efp->subtype == 0 || subtype == efp->subtype ||
 
303
static void DoExceptionFeatureProc (SeqFeatPtr sfp, Pointer userdata)
 
304
{
 
305
  ExceptionFormPtr efp;
 
306
  CharPtr          str;
 
307
  
 
308
  if (sfp == NULL || userdata == NULL) return;
 
309
  efp = (ExceptionFormPtr) userdata;
 
310
 
 
311
  if (efp->subtype == 0 || sfp->idx.subtype == efp->subtype ||
429
312
           (efp->subtype == FEATDEF_IMP &&
430
 
            subtype >= FEATDEF_allele && subtype <= FEATDEF_site_ref)) {
431
 
          if (notext || ExceptionHasSubstring (omtp, aip, (Pointer) sfp, efp)) {
432
 
            sfp->excpt = efp->excpt;
433
 
            if (sfp->excpt) {
434
 
              if (! StringHasNoText (efp->except_text)) {
435
 
                sfp->except_text = MemFree (sfp->except_text);
436
 
                sfp->except_text = StringSave (efp->except_text);
437
 
              }
438
 
            } else {
439
 
              if (efp->rescue) {
440
 
                if (sfp->comment == NULL) {
441
 
                  sfp->comment = sfp->except_text;
442
 
                } else {
443
 
                  str = MemNew (StringLen (sfp->comment) + StringLen (sfp->except_text) + 5);
444
 
                  if (str != NULL) {
445
 
                    StringCpy (str, sfp->comment);
446
 
                    StringCat (str, "; ");
447
 
                    StringCat (str, sfp->except_text);
448
 
                    sfp->comment = MemFree (sfp->comment);
449
 
                    sfp->comment = str;
450
 
                  }
451
 
                }
452
 
                sfp->except_text = NULL;
453
 
              } else {
454
 
                sfp->except_text = MemFree (sfp->except_text);
455
 
              }
 
313
            IsRealImpFeat (sfp->idx.subtype)))
 
314
  {
 
315
    if ((efp->prodval == 1 && sfp->product != NULL) ||
 
316
              (efp->prodval == 2 && sfp->product == NULL) ||
 
317
              efp->prodval == 3)
 
318
    {
 
319
      sfp->excpt = efp->excpt;
 
320
      if (sfp->excpt)
 
321
      {
 
322
        if (! StringHasNoText (efp->except_text)) 
 
323
        {
 
324
          sfp->except_text = MemFree (sfp->except_text);
 
325
          sfp->except_text = StringSave (efp->except_text);
 
326
        }
 
327
      } 
 
328
      else
 
329
      {
 
330
        if (efp->rescue) 
 
331
        {
 
332
          if (sfp->comment == NULL) 
 
333
          {
 
334
            sfp->comment = sfp->except_text;
 
335
          } 
 
336
          else 
 
337
          {
 
338
            str = MemNew (StringLen (sfp->comment) + StringLen (sfp->except_text) + 5);
 
339
            if (str != NULL) 
 
340
            {
 
341
              StringCpy (str, sfp->comment);
 
342
              StringCat (str, "; ");
 
343
              StringCat (str, sfp->except_text);
 
344
              sfp->comment = MemFree (sfp->comment);
 
345
              sfp->comment = str;
456
346
            }
457
347
          }
458
 
        }
459
 
        sfp = sfp->next;
 
348
          sfp->except_text = NULL;
 
349
        }
 
350
        else 
 
351
        {
 
352
          sfp->except_text = MemFree (sfp->except_text);
 
353
        }
460
354
      }
461
355
    }
462
 
    sap = sap->next;
463
356
  }
464
 
  AsnIoClose (aip);
465
357
}
466
358
 
 
359
 
 
360
static CharPtr ExceptionExplanations [] = {
 
361
  "RNA Editing",
 
362
  "reasons given in citation",
 
363
  "ribosomal slippage",
 
364
  "trans splicing",
 
365
  "artificial frameshift",
 
366
  "nonconsensus splice site",
 
367
  "rearrangement required",
 
368
  "other->"
 
369
};
 
370
 
467
371
static void DoException (ButtoN b)
468
372
 
469
373
{
470
 
  ExceptionFormPtr  efp;
471
 
  SeqEntryPtr      sep;
472
 
  Uint2            subtype;
473
 
  Int2             val;
474
 
  ValNodePtr       vnp;
 
374
  ExceptionFormPtr     efp;
 
375
  SeqEntryPtr          sep;
 
376
  Uint2                subtype;
 
377
  Int2                 val;
 
378
  ValNodePtr           vnp;
 
379
  Int4                 explanation_choice;
 
380
  Int4                 num_explanations;
 
381
  FeaturesWithTextData fd;
475
382
 
476
383
  efp = GetObjectExtra (b);
477
384
  if (efp == NULL) return;
494
401
  if (vnp != NULL) {
495
402
    subtype = vnp->choice;
496
403
  }
497
 
  efp->omp = ObjMgrGet ();
498
 
  efp->omtp = NULL;
499
 
  if (efp->omp != NULL) {
500
 
    efp->omtp = ObjMgrTypeFind (efp->omp, efp->itemtype, NULL, NULL);
501
 
  }
502
404
  efp->subtype = subtype;
503
405
  efp->excpt = (Boolean) (GetValue (efp->xception) == 2);
504
406
  if (efp->excpt) {
505
 
    efp->except_text = SaveStringFromText (efp->xceptText);
 
407
    num_explanations = sizeof (ExceptionExplanations) / sizeof (CharPtr);
 
408
    explanation_choice = GetValue (efp->xceptTextPopup);
 
409
    if (explanation_choice > 0 && explanation_choice < num_explanations)
 
410
    {
 
411
      efp->except_text = StringSave (ExceptionExplanations [ explanation_choice - 1]);
 
412
    }
 
413
    else if (explanation_choice == num_explanations)
 
414
    {
 
415
      efp->except_text = SaveStringFromText (efp->xceptText);
 
416
    }
506
417
  } else {
507
418
    efp->except_text = NULL;
508
419
  }
509
420
  efp->rescue = GetStatus (efp->rescueExpl);
510
 
  if (efp->itemtype != 0 && efp->omtp != NULL) {
511
 
    SeqEntryExplore (sep, (Pointer) efp, ExceptionCallback);
512
 
  }
 
421
  efp->prodval = GetValue (efp->prodgrp);
 
422
  GetTitle (efp->findthis, efp->findStr, sizeof (efp->findStr) - 1);
 
423
  
 
424
  fd.search_text = efp->findStr;
 
425
  fd.no_text = StringHasNoText (efp->findStr);
 
426
  fd.seqFeatChoice = 0;
 
427
  fd.featDefChoice = 0;
 
428
  fd.case_insensitive = GetStatus (efp->case_insensitive);
 
429
  fd.act_when_string_not_present = GetStatus (efp->when_string_not_present);
 
430
  fd.callback = DoExceptionFeatureProc;
 
431
  fd.userdata = efp;
 
432
 
 
433
  OperateOnSeqEntryFeaturesWithText (sep, &fd);
 
434
 
513
435
  MemFree (efp->except_text);
514
436
  ArrowCursor ();
515
437
  Update ();
518
440
  Remove (efp->form);
519
441
}
520
442
 
 
443
static void SetExceptionExplanationText (Handle a)
 
444
{
 
445
  ExceptionFormPtr  efp;
 
446
  Int4              explanation_choice;
 
447
  Int4              num_explanations;
 
448
 
 
449
  efp = (ExceptionFormPtr) GetObjectExtra (a);
 
450
  if (efp == NULL) return;
 
451
  
 
452
  num_explanations = sizeof (ExceptionExplanations) / sizeof (CharPtr);
 
453
  
 
454
  explanation_choice = GetValue (efp->xceptTextPopup);
 
455
  if (explanation_choice == num_explanations)
 
456
  {
 
457
    Enable (efp->xceptText);
 
458
  }
 
459
  else
 
460
  {
 
461
    Disable (efp->xceptText);
 
462
    if (explanation_choice > 0 && explanation_choice < num_explanations)
 
463
    {
 
464
      SafeSetTitle (efp->xceptText,
 
465
                    ExceptionExplanations [ explanation_choice - 1]);
 
466
    }
 
467
  } 
 
468
}
 
469
 
 
470
static void BuildExceptionExplanationGroup (
 
471
  ExceptionFormPtr efp,
 
472
  GrouP r
 
473
)
 
474
{
 
475
  Int4 i;
 
476
  Int4 num_explanations;
 
477
 
 
478
  if (efp == NULL || r == NULL) return;
 
479
 
 
480
  num_explanations = sizeof (ExceptionExplanations) / sizeof (CharPtr);
 
481
 
 
482
  StaticPrompt (r, "Explanation", 0, dialogTextHeight, programFont, 'l');
 
483
  efp->xceptTextPopup = PopupList (r, TRUE,
 
484
                                   (PupActnProc) SetExceptionExplanationText);
 
485
  SetObjectExtra (efp->xceptTextPopup, efp, NULL);
 
486
  for (i = 0; i < num_explanations; i++)
 
487
  {
 
488
    PopupItem (efp->xceptTextPopup, ExceptionExplanations [i]);
 
489
  }
 
490
  SetValue (efp->xceptTextPopup, 1);
 
491
 
 
492
  efp->xceptText = DialogText (r, "", 12, NULL);
 
493
  SafeSetTitle (efp->xceptText,
 
494
                ExceptionExplanations [ 0 ]);
 
495
  Disable (efp->xceptText);
 
496
}
 
497
 
521
498
static void ExceptionMessageProc (ForM f, Int2 mssg)
522
499
 
523
500
{
549
526
  BaseFormPtr        bfp;
550
527
  ButtoN             b;
551
528
  GrouP              c;
552
 
  FeatDefPtr         curr;
553
529
  ExceptionFormPtr   efp;
554
530
  GrouP              g;
555
531
  GrouP              h;
556
532
  ValNodePtr         head;
 
533
  GrouP              j;
557
534
  GrouP              k;
558
 
  Uint1              key;
559
 
  CharPtr            label = NULL;
560
535
  Int2               listHeight;
561
536
  PrompT             ppt;
562
 
  GrouP              q;
 
537
  GrouP              q, r;
563
538
  SeqEntryPtr        sep;
564
539
  StdEditorProcsPtr  sepp;
565
 
  Uint2              subtype;
566
540
  ValNodePtr         vnp;
567
541
  WindoW             w;
568
542
 
602
576
    listHeight = 8;
603
577
  }
604
578
  efp->objlist = SingleList (g, 16, listHeight, NULL);
605
 
  head = ValNodeNew (NULL);
606
 
  if (head != NULL) {
607
 
    head->choice = 0;
608
 
    head->data.ptrvalue = StringSave ("[ALL FEATURES]");
609
 
  }
610
 
  curr = FeatDefFindNext (NULL, &key, &label, FEATDEF_ANY, TRUE);
611
 
  while (curr != NULL) {
612
 
    if (key != FEATDEF_BAD) {
613
 
      subtype = curr->featdef_key;
614
 
      if (subtype != FEATDEF_misc_RNA &&
615
 
          subtype != FEATDEF_precursor_RNA &&
616
 
          subtype != FEATDEF_mat_peptide &&
617
 
          subtype != FEATDEF_sig_peptide &&
618
 
          subtype != FEATDEF_transit_peptide) {
619
 
        vnp = ValNodeNew (head);
620
 
        /* if (head == NULL) {
621
 
          head = vnp;
622
 
        } */
623
 
        if (vnp != NULL) {
624
 
          vnp->choice = subtype;
625
 
          vnp->data.ptrvalue = StringSave (curr->typelabel);
626
 
        }
627
 
      }
628
 
    }
629
 
    curr = FeatDefFindNext (curr, &key, &label, FEATDEF_ANY, TRUE);
630
 
  }
631
 
  if (head != NULL) {
632
 
    head = SortValNode (head, SortByVnpChoice);
 
579
  head = BuildFeatureValNodeList (TRUE, "[ALL FEATURES]", 0, FALSE, TRUE);
 
580
  if (head != NULL) {
633
581
    for (vnp = head; vnp != NULL; vnp = vnp->next) {
634
582
      ListItem (efp->objlist, (CharPtr) vnp->data.ptrvalue);
635
583
    }
643
591
  RadioButton (efp->xception, "Clear");
644
592
  RadioButton (efp->xception, "Set");
645
593
  SetValue (efp->xception, 1);
646
 
  StaticPrompt (q, "Explanation", 0, dialogTextHeight, programFont, 'l');
647
 
  efp->xceptText = DialogText (q, "", 12, NULL);
648
594
  AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt, (HANDLE) efp->xception, NULL);
649
 
  efp->rescueExpl = CheckBox (q, "Move explanation to comment", NULL);
 
595
  r = HiddenGroup (h, 3, 0, NULL);
 
596
/*  SetGroupSpacing (r, 10, 10); */
 
597
  BuildExceptionExplanationGroup (efp, r);
 
598
  efp->rescueExpl = CheckBox (h, "Move explanation to comment", NULL);
650
599
 
651
 
  k = HiddenGroup (h, 0, 2, NULL);
 
600
  k = HiddenGroup (h, 0, 4, NULL);
652
601
  StaticPrompt (k, "Optional string constraint", 0, dialogTextHeight, programFont, 'c');
653
602
  efp->findthis = DialogText (k, "", 14, NULL);
 
603
  efp->case_insensitive = CheckBox (k, "Case Insensitive", NULL);
 
604
  efp->when_string_not_present = CheckBox (k, "When String is Not Present", NULL);
 
605
 
 
606
  j = HiddenGroup (h, -2, 0, NULL);
 
607
  StaticPrompt (j, "Feature Product", 0, dialogTextHeight, programFont, 'c');
 
608
  efp->prodgrp = HiddenGroup (j, -3, 0, NULL);
 
609
  SetObjectExtra (efp->prodgrp, efp, NULL);
 
610
  RadioButton (efp->prodgrp, "Present");
 
611
  RadioButton (efp->prodgrp, "Absent");
 
612
  RadioButton (efp->prodgrp, "Either");
 
613
  SetValue (efp->prodgrp, 3);
654
614
 
655
615
  c = HiddenGroup (h, 4, 0, NULL);
656
 
  b = PushButton (c, "Accept", DoException);
 
616
  b = DefaultButton (c, "Accept", DoException);
657
617
  SetObjectExtra (b, efp, NULL);
658
618
  PushButton (c, "Cancel", StdCancelButtonProc);
659
619
 
660
 
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) q, (HANDLE) k, (HANDLE) c, NULL);
 
620
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) q, (HANDLE) r, (HANDLE) efp->rescueExpl, (HANDLE) k, (HANDLE) j, (HANDLE) c, NULL);
661
621
  RealizeWindow (w);
662
622
  Show (w);
663
623
  Update ();
737
697
  bssp = (BioseqSetPtr) sep->data.ptrvalue;
738
698
  if (bssp == NULL) return;
739
699
  _class = bssp->_class;
740
 
  if (_class != 7 && _class != 13 && _class != 14 && _class != 15) return;
 
700
  if (_class != 7 && _class != 13 && _class != 14 &&
 
701
      _class != 15 && _class != 16 && _class != 18) return;
741
702
 
742
703
  SaveSeqEntryObjMgrData (sep, &omdptop, &omdata);
743
704
  GetSeqEntryParent (sep, &parentptr, &parenttype);
857
818
  MonitorPtr  mon;
858
819
  BioseqPtr   batchbsp;
859
820
  Boolean     include_stop;
 
821
  Boolean     no_stop_at_end_of_complete_cds;
860
822
} RecompData, PNTR RecompDataPtr;
861
823
 
862
824
static Int2 GeneticCodeFromCrp (CdRegionPtr crp)
904
866
  return code;
905
867
}
906
868
 
907
 
static Boolean RecomputeSuggCallback (GatherContextPtr gcp)
 
869
extern void ExtendSeqLocToEnd (SeqLocPtr slp, BioseqPtr bsp, Boolean end5)
 
870
{
 
871
  Uint1          strand;
 
872
  SeqLocPtr      slp_to_change, slp_index;
 
873
  Int4           extent_to_change;
 
874
  Int4           start, stop;
 
875
  SeqIdPtr       sip;
 
876
  
 
877
  if (slp == NULL || bsp == NULL) return;
 
878
 
 
879
  slp_to_change = NULL;
 
880
  strand = SeqLocStrand (slp);
 
881
  switch (slp->choice)
 
882
  {
 
883
    case SEQLOC_INT:
 
884
      slp_to_change = slp;
 
885
      break;
 
886
    case SEQLOC_MIX:
 
887
        case SEQLOC_PACKED_INT:
 
888
      sip = SeqLocId (slp);
 
889
      if (sip == NULL) return; /* can only process if all on one bioseq */
 
890
      slp_to_change = NULL;
 
891
      if ((strand == Seq_strand_minus && end5)
 
892
        || (strand != Seq_strand_minus && !end5))
 
893
      {
 
894
        extent_to_change = 0;
 
895
        for (slp_index = (SeqLocPtr)slp->data.ptrvalue; slp_index != NULL; slp_index = slp_index->next)
 
896
        {
 
897
          stop = GetOffsetInBioseq (slp_index, bsp, SEQLOC_STOP);
 
898
          if (stop > extent_to_change)
 
899
          {
 
900
            slp_to_change = slp_index;
 
901
            extent_to_change = stop;
 
902
          }
 
903
        }
 
904
      }
 
905
      else
 
906
      {
 
907
        extent_to_change = bsp->length;
 
908
        for (slp_index = (SeqLocPtr)slp->data.ptrvalue; slp_index != NULL; slp_index = slp_index->next)
 
909
        {
 
910
          start = GetOffsetInBioseq (slp_index, bsp, SEQLOC_START);
 
911
          if (start < extent_to_change)
 
912
          {
 
913
            slp_to_change = slp_index;
 
914
            extent_to_change = start;
 
915
          }
 
916
        }
 
917
      }
 
918
      break;
 
919
  }
 
920
 
 
921
  if (slp_to_change != NULL)
 
922
  {
 
923
    if ((strand == Seq_strand_minus && end5)
 
924
      || (strand != Seq_strand_minus && !end5))
 
925
    {
 
926
      start = GetOffsetInBioseq (slp_to_change, bsp, SEQLOC_START);
 
927
      stop = bsp->length - 1;
 
928
    }
 
929
    else
 
930
    {
 
931
      start = 0;
 
932
      stop = GetOffsetInBioseq (slp_to_change, bsp, SEQLOC_STOP);
 
933
    }
 
934
    expand_seq_loc (start, stop, strand, slp_to_change);
 
935
  }
 
936
}
 
937
 
 
938
static void ExtendOnePartialFeature (SeqFeatPtr sfp, Pointer userdata)
 
939
{
 
940
  BioseqPtr bsp;
 
941
  Boolean   partial3, partial5;
 
942
 
 
943
  if (sfp == NULL) return;
 
944
  bsp = BioseqFindFromSeqLoc (sfp->location);
 
945
  if (bsp == NULL) return;
 
946
  CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
 
947
  if (partial5)
 
948
  {
 
949
    ExtendSeqLocToEnd (sfp->location, bsp, TRUE);
 
950
  }
 
951
  if (partial3)
 
952
  {
 
953
    ExtendSeqLocToEnd (sfp->location, bsp, FALSE);
 
954
  }
 
955
}
 
956
 
 
957
extern void ExtendPartialFeatures (IteM i)
 
958
{
 
959
  BaseFormPtr       bfp;
 
960
  SeqEntryPtr       sep;
 
961
  SelStructPtr      sel;
 
962
  SeqFeatPtr        sfp;
 
963
  SeqMgrFeatContext fcontext;
 
964
 
 
965
#ifdef WIN_MAC
 
966
  bfp = currentFormDataPtr;
 
967
#else
 
968
  bfp = GetObjectExtra (i);
 
969
#endif
 
970
  if (bfp == NULL) return;
 
971
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
972
  if (sep == NULL) return;
 
973
  sel = ObjMgrGetSelected ();
 
974
  WatchCursor ();
 
975
  Update ();
 
976
  if (sel == NULL)
 
977
  {
 
978
    VisitFeaturesInSep (sep, NULL, ExtendOnePartialFeature);
 
979
  }
 
980
  else
 
981
  {
 
982
    while (sel != NULL)
 
983
    {
 
984
      if (sel->entityID == bfp->input_entityID
 
985
        && sel->itemtype == OBJ_SEQFEAT)
 
986
      {
 
987
        sfp = SeqMgrGetDesiredFeature (bfp->input_entityID, NULL, sel->itemID, 0, NULL, &fcontext);
 
988
        if (sfp != NULL)
 
989
        {
 
990
          ExtendOnePartialFeature (sfp, NULL);
 
991
        }
 
992
      }
 
993
      sel = sel->next;
 
994
    }
 
995
  }
 
996
  ArrowCursor ();
 
997
  Update ();
 
998
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
999
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
1000
}
 
1001
 
 
1002
static Boolean HasValidStartCodon (SeqFeatPtr cds)
 
1003
{
 
1004
  ByteStorePtr  bs;
 
1005
  CharPtr       prot;
 
1006
 
 
1007
  if (cds == NULL) return FALSE;
 
1008
 
 
1009
  bs = ProteinFromCdRegionEx (cds, TRUE, FALSE);
 
1010
 
 
1011
  if (bs == NULL) return FALSE;
 
1012
  prot = BSMerge (bs, NULL);
 
1013
  bs = BSFree (bs);
 
1014
  if (prot == NULL) return FALSE;
 
1015
  if (prot [0] != 'M') return FALSE;
 
1016
  return TRUE;
 
1017
}
 
1018
 
 
1019
static void FixReadingFrame (
 
1020
  CdRegionPtr crp,
 
1021
  SeqLocPtr slp,
 
1022
  BioseqPtr bsp,
 
1023
  Int4 start
 
1024
)
 
1025
{
 
1026
  Int4 offset;
 
1027
 
 
1028
  if (crp == NULL || slp == NULL) return;
 
1029
 
 
1030
  if (SeqLocStrand (slp) == Seq_strand_minus)
 
1031
  {
 
1032
    offset = bsp->length - start;
 
1033
  }
 
1034
  else
 
1035
  {
 
1036
    offset = start;
 
1037
  }
 
1038
  start = start % 3;
 
1039
  start = start + 1;
 
1040
  crp->frame = start;
 
1041
}
 
1042
 
 
1043
static void RecomputeSuggestedIntervalsForCDS (
 
1044
  RecompDataPtr rdp,
 
1045
  SeqFeatPtr    sfp,
 
1046
  Uint2         entityID
 
1047
)
908
1048
 
909
1049
{
910
1050
  Int2           code;
911
1051
  CdRegionPtr    crp;
912
1052
  BioseqPtr      nucbsp;
913
1053
  BioseqPtr      protbsp;
914
 
  RecompDataPtr  rdp;
915
 
  SeqFeatPtr     sfp;
916
1054
  SeqIdPtr       sip;
917
1055
  SeqLocPtr      slp;
918
1056
  Char           str [256];
919
1057
  Char           tmp [256];
 
1058
  Boolean        partial3, partial5;
 
1059
  Int4           start;
920
1060
 
921
 
  if (gcp == NULL) return TRUE;
922
 
  if (gcp->thistype != OBJ_SEQFEAT) return TRUE;
923
 
  rdp = (RecompDataPtr) gcp->userdata;
924
 
  if (rdp == NULL) return TRUE;
925
 
  sfp = (SeqFeatPtr) gcp->thisitem;
926
 
  if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) return TRUE;
 
1061
  if (rdp == NULL) return;
 
1062
  if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) return;
927
1063
  crp = (CdRegionPtr) sfp->data.value.ptrvalue;
928
 
  if (crp == NULL) return TRUE;
929
 
  /* if (CdsTranslatesProperly (sfp, gcp)) return TRUE; */
 
1064
  if (crp == NULL) return;
930
1065
 
931
1066
  code = GeneticCodeFromCrp (crp);
932
1067
 
933
 
  nucbsp = GetBioseqGivenSeqLoc (sfp->location, gcp->entityID);
 
1068
  nucbsp = GetBioseqGivenSeqLoc (sfp->location, entityID);
934
1069
  if (nucbsp != NULL && rdp->batchbsp != NULL && nucbsp != rdp->batchbsp) {
935
1070
    ClearBatchSuggestNucleotide ();
936
 
    rdp->batchbsp = NULL;
937
 
    Message (MSG_POSTERR, "Recompute Suggest is reverting to slower processing");
 
1071
    rdp->batchbsp = nucbsp;
 
1072
    SetBatchSuggestNucleotide (rdp->batchbsp, code);
 
1073
/*    Message (MSG_POSTERR, "Recompute Suggest is reverting to slower processing"); */
938
1074
  }
939
1075
  sip = SeqLocId (sfp->product);
940
1076
  if (sip != NULL) {
953
1089
        Update ();
954
1090
      }
955
1091
      slp = PredictCodingRegion (nucbsp, protbsp, code);
956
 
      if (slp == NULL) return TRUE;
 
1092
      if (slp == NULL) return;
 
1093
 
 
1094
      /* correct for partial conditions */
 
1095
      CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
 
1096
 
957
1097
      sfp->location = SeqLocFree (sfp->location);
958
1098
      sfp->location = slp;
 
1099
 
 
1100
      /* if no valid start codon, cds is 5' partial */
 
1101
      if (! HasValidStartCodon (sfp))
 
1102
      {
 
1103
        partial5 = TRUE;
 
1104
      }
 
1105
 
 
1106
      if (partial5 || partial3)
 
1107
      {
 
1108
        if (partial5)
 
1109
        {
 
1110
          start = GetOffsetInBioseq (sfp->location, nucbsp, SEQLOC_START);
 
1111
          ExtendSeqLocToEnd (sfp->location, nucbsp, TRUE);
 
1112
          FixReadingFrame (crp, sfp->location, nucbsp, start);
 
1113
        }
 
1114
        if (partial3)
 
1115
        {
 
1116
          ExtendSeqLocToEnd (sfp->location, nucbsp, FALSE);
 
1117
        }
 
1118
        SetSeqLocPartial (sfp->location, partial5, partial3);
 
1119
      }
959
1120
      sfp->partial = LocationHasNullsBetween (sfp->location);
 
1121
      sfp->partial |= partial5 || partial3;
960
1122
    }
961
1123
  }
 
1124
}
 
1125
 
 
1126
static Boolean RecomputeSuggCallback (GatherContextPtr gcp)
 
1127
{
 
1128
  RecompDataPtr  rdp;
 
1129
  SeqFeatPtr     sfp;
 
1130
 
 
1131
  if (gcp == NULL) return TRUE;
 
1132
  if (gcp->thistype != OBJ_SEQFEAT) return TRUE;
 
1133
  rdp = (RecompDataPtr) gcp->userdata;
 
1134
  if (rdp == NULL) return TRUE;
 
1135
  sfp = (SeqFeatPtr) gcp->thisitem;
 
1136
  if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) return TRUE;
 
1137
 
 
1138
  RecomputeSuggestedIntervalsForCDS (rdp, sfp, gcp->entityID);
962
1139
  return TRUE;
963
1140
}
964
1141
 
965
1142
extern void RecomputeSuggest (IteM i)
966
1143
 
967
1144
{
968
 
  BaseFormPtr  bfp;
969
 
  Int2         code;
970
 
  GatherScope  gs;
971
 
  SeqEntryPtr  nucsep;
972
 
  RecompData   rd;
973
 
  SeqEntryPtr  sep;
 
1145
  BaseFormPtr       bfp;
 
1146
  Int2              code;
 
1147
  GatherScope       gs;
 
1148
  SeqEntryPtr       nucsep;
 
1149
  RecompData        rd;
 
1150
  SeqEntryPtr       sep;
 
1151
  SelStructPtr      sel;
 
1152
  SeqFeatPtr        sfp;
 
1153
  SeqMgrFeatContext fcontext;
974
1154
 
975
1155
#ifdef WIN_MAC
976
1156
  bfp = currentFormDataPtr;
980
1160
  if (bfp == NULL) return;
981
1161
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
982
1162
  if (sep == NULL) return;
 
1163
  sel = ObjMgrGetSelected ();
983
1164
  WatchCursor ();
984
1165
  Update ();
985
1166
  rd.count = 0;
986
1167
  rd.mon = MonitorStrNewEx ("Correcting Coding Regions", 20, FALSE);
987
1168
  rd.batchbsp = NULL;
 
1169
  rd.no_stop_at_end_of_complete_cds = FALSE;
988
1170
  nucsep = FindNucSeqEntry (sep);
989
1171
  if (nucsep != NULL && IS_Bioseq (nucsep)) {
990
1172
    rd.batchbsp = (BioseqPtr) nucsep->data.ptrvalue;
993
1175
    code = SeqEntryToGeneticCode (sep, NULL, NULL, 0);
994
1176
    SetBatchSuggestNucleotide (rd.batchbsp, code);
995
1177
  }
996
 
  MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
997
 
  gs.seglevels = 1;
998
 
  gs.get_feats_location = FALSE;
999
 
  MemSet((Pointer)(gs.ignore), (int)(TRUE), (size_t)(OBJ_MAX * sizeof(Boolean)));
1000
 
  gs.ignore[OBJ_BIOSEQ] = FALSE;
1001
 
  gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
1002
 
  gs.ignore[OBJ_SEQFEAT] = FALSE;
1003
 
  gs.ignore[OBJ_SEQANNOT] = FALSE;
1004
 
  GatherEntity (bfp->input_entityID, (Pointer) (&rd), RecomputeSuggCallback, &gs);
 
1178
  if (sel == NULL)
 
1179
  {
 
1180
    MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
 
1181
    gs.seglevels = 1;
 
1182
    gs.get_feats_location = FALSE;
 
1183
    MemSet((Pointer)(gs.ignore), (int)(TRUE), (size_t)(OBJ_MAX * sizeof(Boolean)));
 
1184
    gs.ignore[OBJ_BIOSEQ] = FALSE;
 
1185
    gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
 
1186
    gs.ignore[OBJ_SEQFEAT] = FALSE;
 
1187
    gs.ignore[OBJ_SEQANNOT] = FALSE;
 
1188
    GatherEntity (bfp->input_entityID, (Pointer) (&rd), RecomputeSuggCallback, &gs);
 
1189
  }
 
1190
  else
 
1191
  {
 
1192
    while (sel != NULL)
 
1193
    {
 
1194
      if (sel->entityID == bfp->input_entityID
 
1195
        && sel->itemtype == OBJ_SEQFEAT)
 
1196
      {
 
1197
        sfp = SeqMgrGetDesiredFeature (bfp->input_entityID, NULL, sel->itemID, 0, NULL, &fcontext);
 
1198
        if (sfp != NULL && sfp->idx.subtype == FEATDEF_CDS)
 
1199
        {
 
1200
          RecomputeSuggestedIntervalsForCDS (&rd, sfp, bfp->input_entityID);
 
1201
        }
 
1202
      }
 
1203
      sel = sel->next;
 
1204
    }
 
1205
  }
1005
1206
  MonitorFree (rd.mon);
1006
1207
  if (rd.batchbsp != NULL) {
1007
1208
    ClearBatchSuggestNucleotide ();
1012
1213
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
1013
1214
}
1014
1215
 
1015
 
static Boolean RetranslateOneCDS (SeqFeatPtr sfp, Uint2 entityID, Boolean include_stop)
 
1216
static Boolean RetranslateOneCDS (
 
1217
  SeqFeatPtr sfp,
 
1218
  Uint2 entityID,
 
1219
  Boolean include_stop,
 
1220
  Boolean no_stop_at_end_of_complete_cds
 
1221
)
1016
1222
 
1017
1223
{
1018
1224
  SeqFeatPtr    bestprot;
1019
1225
  ByteStorePtr  bs;
1020
1226
  BioseqPtr     bsp;
1021
1227
  Char          ch;
 
1228
  SeqFeatPtr    gene;
 
1229
  GeneRefPtr    grp;
1022
1230
  SeqEntryPtr   master;
1023
1231
  MolInfoPtr    mip;
1024
1232
  SeqEntryPtr   old;
1028
1236
  CharPtr       ptr;
1029
1237
  SeqEntryPtr   sep;
1030
1238
  SeqIdPtr      sip;
1031
 
  SeqLocPtr     slp;
1032
1239
  ValNodePtr    vnp;
1033
1240
 
1034
1241
  if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) return TRUE;
1035
 
  slp = SeqLocFindNext (sfp->location, NULL);
1036
 
  if (slp == NULL) return TRUE;
1037
 
  CheckSeqLocForPartial (slp, &partial5, &partial3);
 
1242
 
 
1243
  /* bail on pseudo CDS */
 
1244
 
 
1245
  if (sfp->pseudo) return TRUE;
 
1246
  grp = SeqMgrGetGeneXref (sfp);
 
1247
  if (grp != NULL) {
 
1248
    if (grp->pseudo) return TRUE;
 
1249
  } else {
 
1250
    gene = SeqMgrGetOverlappingGene (sfp->location, NULL);
 
1251
    if (gene != NULL) {
 
1252
      if (gene->pseudo) return TRUE;
 
1253
      grp = (GeneRefPtr) gene->data.value.ptrvalue;
 
1254
      if (grp != NULL && grp->pseudo) return TRUE;
 
1255
    }
 
1256
  }
 
1257
 
 
1258
  if (sfp->location == NULL) return TRUE;
 
1259
  CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
1038
1260
  /* if (CdsTranslatesProperly (sfp, gcp)) return TRUE; */
1039
1261
 
1040
1262
  if (sfp->product == NULL) {
1077
1299
    bsp = BioseqFind (sip);
1078
1300
    if (bsp != NULL && ISA_aa (bsp->mol) && bsp->repr == Seq_repr_raw) {
1079
1301
      bestprot = FindBestProtein (entityID, sfp->product);
1080
 
      bs = ProteinFromCdRegionEx (sfp, include_stop, FALSE);
 
1302
      bs = ProteinFromCdRegionExWithTrailingCodonHandling (sfp,
 
1303
                                              include_stop,
 
1304
                                              FALSE,
 
1305
                                              no_stop_at_end_of_complete_cds );
1081
1306
      if (bs == NULL) return TRUE;
1082
1307
      prot = BSMerge (bs, NULL);
1083
1308
      bs = BSFree (bs);
1159
1384
  rdp = (RecompDataPtr) gcp->userdata;
1160
1385
  if (rdp == NULL) return TRUE;
1161
1386
  sfp = (SeqFeatPtr) gcp->thisitem;
1162
 
  return RetranslateOneCDS (sfp, gcp->entityID, rdp->include_stop);
 
1387
  return RetranslateOneCDS (sfp, gcp->entityID, rdp->include_stop,
 
1388
                            rdp->no_stop_at_end_of_complete_cds);
1163
1389
}
1164
1390
 
1165
 
static void RetranslateCdRegions (IteM i, Boolean include_stop)
 
1391
static void RetranslateCdRegions (
 
1392
  IteM i,
 
1393
  Boolean include_stop,
 
1394
  Boolean no_stop_at_end_of_complete_cds )
1166
1395
 
1167
1396
{
1168
1397
  BaseFormPtr  bfp;
1183
1412
  rd.count = 0;
1184
1413
  rd.mon = MonitorStrNewEx ("Correcting Coding Regions", 20, FALSE);
1185
1414
  rd.include_stop = include_stop;
 
1415
  rd.no_stop_at_end_of_complete_cds = no_stop_at_end_of_complete_cds;
1186
1416
  MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
1187
1417
  gs.seglevels = 1;
1188
1418
  gs.get_feats_location = FALSE;
1202
1432
extern void RetranslateCdRegionsNoStop (IteM i)
1203
1433
 
1204
1434
{
1205
 
  RetranslateCdRegions (i, FALSE);
 
1435
  RetranslateCdRegions (i, FALSE, FALSE);
1206
1436
}
1207
1437
 
1208
1438
extern void RetranslateCdRegionsDoStop (IteM i)
1209
1439
 
1210
1440
{
1211
 
  RetranslateCdRegions (i, TRUE);
 
1441
  RetranslateCdRegions (i, TRUE, FALSE);
 
1442
}
 
1443
 
 
1444
extern void RetranslateCdRegionsNoStopExceptEndCompleteCDS (IteM i)
 
1445
{
 
1446
  RetranslateCdRegions (i, TRUE, TRUE);
 
1447
}
 
1448
 
 
1449
 
 
1450
static void DoReprocessPeptides (SeqFeatPtr sfp, Pointer userdata)
 
1451
 
 
1452
{
 
1453
  SeqFeatPtr    bestprot;
 
1454
  ByteStorePtr  bs;
 
1455
  BioseqPtr     bsp;
 
1456
  Char          ch;
 
1457
  MolInfoPtr    mip;
 
1458
  Boolean       partial5;
 
1459
  Boolean       partial3;
 
1460
  CharPtr       prot;
 
1461
  ProtRefPtr    prp;
 
1462
  CharPtr       ptr;
 
1463
  SeqEntryPtr   sep;
 
1464
  SeqIdPtr      sip;
 
1465
  ValNodePtr    vnp;
 
1466
 
 
1467
  if (sfp->data.choice != SEQFEAT_PROT) return;
 
1468
  if (sfp->product == NULL) return;
 
1469
  prp = (ProtRefPtr) sfp->data.value.ptrvalue;
 
1470
  if (prp == NULL) return;
 
1471
  if (prp->processed < 1 || prp->processed > 4) return;
 
1472
  CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
 
1473
  sip = SeqLocId (sfp->product);
 
1474
  if (sip == NULL) return;
 
1475
  bsp = BioseqFind (sip);
 
1476
  if (bsp != NULL && ISA_aa (bsp->mol) && bsp->repr == Seq_repr_raw) {
 
1477
    bestprot = FindBestProtein (sfp->idx.entityID, sfp->product);
 
1478
    prot = GetSequenceByFeature (sfp);
 
1479
    if (prot == NULL) return;
 
1480
    ptr = prot;
 
1481
    ch = *ptr;
 
1482
    while (ch != '\0') {
 
1483
      *ptr = TO_UPPER (ch);
 
1484
      ptr++;
 
1485
      ch = *ptr;
 
1486
    }
 
1487
    bs = BSNew (1000);
 
1488
    if (bs != NULL) {
 
1489
      ptr = prot;
 
1490
      BSWrite (bs, (VoidPtr) ptr, (Int4) StringLen (ptr));
 
1491
    }
 
1492
    bsp->repr = Seq_repr_raw;
 
1493
    bsp->mol = Seq_mol_aa;
 
1494
    bsp->seq_data_type = Seq_code_ncbieaa;
 
1495
    bsp->seq_data = BSFree (bsp->seq_data);
 
1496
    bsp->seq_data = bs;
 
1497
    bsp->length = BSLen (bs);
 
1498
    sep = SeqMgrGetSeqEntryForData (bsp);
 
1499
    if (sep == NULL) return;
 
1500
    if (bestprot != NULL) {
 
1501
      bestprot->location = SeqLocFree (bestprot->location);
 
1502
      bestprot->location = CreateWholeInterval (sep);
 
1503
      SetSeqLocPartial (bestprot->location, partial5, partial3);
 
1504
      bestprot->partial = (partial5 || partial3);
 
1505
    }
 
1506
    vnp = SeqEntryGetSeqDescr (sep, Seq_descr_molinfo, NULL);
 
1507
    if (vnp == NULL) {
 
1508
      vnp = CreateNewDescriptor (sep, Seq_descr_molinfo);
 
1509
      if (vnp != NULL) {
 
1510
        mip = MolInfoNew ();
 
1511
        vnp->data.ptrvalue = (Pointer) mip;
 
1512
        if (mip != NULL) {
 
1513
          mip->biomol = 8;
 
1514
          mip->tech = 13;
 
1515
        }
 
1516
      }
 
1517
    }
 
1518
    if (vnp != NULL) {
 
1519
      mip = (MolInfoPtr) vnp->data.ptrvalue;
 
1520
      if (mip != NULL) {
 
1521
        if (partial5 && partial3) {
 
1522
          mip->completeness = 5;
 
1523
        } else if (partial5) {
 
1524
          mip->completeness = 3;
 
1525
        } else if (partial3) {
 
1526
          mip->completeness = 4;
 
1527
        /*
 
1528
        } else if (partial) {
 
1529
          mip->completeness = 2;
 
1530
        */
 
1531
        } else {
 
1532
          mip->completeness = 0;
 
1533
        }
 
1534
      }
 
1535
    }
 
1536
  }
 
1537
}
 
1538
 
 
1539
extern void ReprocessPeptideProducts (IteM i);
 
1540
extern void ReprocessPeptideProducts (IteM i)
 
1541
 
 
1542
{
 
1543
  BaseFormPtr  bfp;
 
1544
  SeqEntryPtr  sep;
 
1545
 
 
1546
#ifdef WIN_MAC
 
1547
  bfp = currentFormDataPtr;
 
1548
#else
 
1549
  bfp = GetObjectExtra (i);
 
1550
#endif
 
1551
  if (bfp == NULL) return;
 
1552
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
1553
  if (sep == NULL) return;
 
1554
  VisitFeaturesInSep (sep, NULL, DoReprocessPeptides);
 
1555
  Update ();
 
1556
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
1557
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
1558
}
 
1559
 
 
1560
static void DoReprocessMrnas (SeqFeatPtr sfp, Pointer userdata)
 
1561
 
 
1562
{
 
1563
  ByteStorePtr  bs;
 
1564
  BioseqPtr     bsp;
 
1565
  Char          ch;
 
1566
  MolInfoPtr    mip;
 
1567
  Boolean       partial5;
 
1568
  Boolean       partial3;
 
1569
  CharPtr       prot;
 
1570
  CharPtr       ptr;
 
1571
  RnaRefPtr     rrp;
 
1572
  SeqEntryPtr   sep;
 
1573
  SeqIdPtr      sip;
 
1574
  ValNodePtr    vnp;
 
1575
 
 
1576
  if (sfp->data.choice != SEQFEAT_RNA) return;
 
1577
  if (sfp->product == NULL) return;
 
1578
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
1579
  if (rrp == NULL) return;
 
1580
  if (rrp->type != 2) return;
 
1581
  CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
 
1582
  sip = SeqLocId (sfp->product);
 
1583
  if (sip == NULL) return;
 
1584
  bsp = BioseqFind (sip);
 
1585
  if (bsp != NULL && ISA_na (bsp->mol) && bsp->repr == Seq_repr_raw) {
 
1586
    prot = GetSequenceByFeature (sfp);
 
1587
    if (prot == NULL) return;
 
1588
    ptr = prot;
 
1589
    ch = *ptr;
 
1590
    while (ch != '\0') {
 
1591
      *ptr = TO_UPPER (ch);
 
1592
      ptr++;
 
1593
      ch = *ptr;
 
1594
    }
 
1595
    bs = BSNew (1000);
 
1596
    if (bs != NULL) {
 
1597
      ptr = prot;
 
1598
      BSWrite (bs, (VoidPtr) ptr, (Int4) StringLen (ptr));
 
1599
    }
 
1600
    bsp->repr = Seq_repr_raw;
 
1601
    bsp->mol = Seq_mol_na;
 
1602
    bsp->seq_data_type = Seq_code_iupacna;
 
1603
    bsp->seq_data = BSFree (bsp->seq_data);
 
1604
    bsp->seq_data = bs;
 
1605
    bsp->length = BSLen (bs);
 
1606
    sep = SeqMgrGetSeqEntryForData (bsp);
 
1607
    if (sep == NULL) return;
 
1608
    vnp = SeqEntryGetSeqDescr (sep, Seq_descr_molinfo, NULL);
 
1609
    if (vnp == NULL) {
 
1610
      vnp = CreateNewDescriptor (sep, Seq_descr_molinfo);
 
1611
      if (vnp != NULL) {
 
1612
        mip = MolInfoNew ();
 
1613
        vnp->data.ptrvalue = (Pointer) mip;
 
1614
        if (mip != NULL) {
 
1615
          mip->biomol = 8;
 
1616
          mip->tech = 13;
 
1617
        }
 
1618
      }
 
1619
    }
 
1620
    if (vnp != NULL) {
 
1621
      mip = (MolInfoPtr) vnp->data.ptrvalue;
 
1622
      if (mip != NULL) {
 
1623
        if (partial5 && partial3) {
 
1624
          mip->completeness = 5;
 
1625
        } else if (partial5) {
 
1626
          mip->completeness = 3;
 
1627
        } else if (partial3) {
 
1628
          mip->completeness = 4;
 
1629
        /*
 
1630
        } else if (partial) {
 
1631
          mip->completeness = 2;
 
1632
        */
 
1633
        } else {
 
1634
          mip->completeness = 0;
 
1635
        }
 
1636
      }
 
1637
    }
 
1638
  }
 
1639
}
 
1640
 
 
1641
extern void ReprocessmRNAProducts (IteM i);
 
1642
extern void ReprocessmRNAProducts (IteM i)
 
1643
 
 
1644
{
 
1645
  BaseFormPtr  bfp;
 
1646
  SeqEntryPtr  sep;
 
1647
 
 
1648
#ifdef WIN_MAC
 
1649
  bfp = currentFormDataPtr;
 
1650
#else
 
1651
  bfp = GetObjectExtra (i);
 
1652
#endif
 
1653
  if (bfp == NULL) return;
 
1654
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
1655
  if (sep == NULL) return;
 
1656
  VisitFeaturesInSep (sep, NULL, DoReprocessMrnas);
 
1657
  Update ();
 
1658
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
1659
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
1660
}
 
1661
 
 
1662
/*
 
1663
 * ApplyCodeBreakToCDS
 
1664
 */
 
1665
 
 
1666
static Boolean ApplyCodeBreakToCDS (SeqFeatPtr sfp, CharPtr codonStr, Int2 aaNum)
 
1667
{
 
1668
  Uint1            aaChar;
 
1669
  SeqLocPtr        aaSlp;
 
1670
  Int4             aaPosition;
 
1671
  SeqPntPtr        aaSpp;
 
1672
  CharPtr          basePtr;
 
1673
  CharPtr          bases;
 
1674
  CodeBreakPtr     cbp;
 
1675
  CdRegionPtr      crp;
 
1676
  Int4             dnaLen;
 
1677
  SeqLocPtr        dnaSlp;
 
1678
  CodeBreakPtr     lastCbp;
 
1679
  SeqCodeTablePtr  sctp;
 
1680
  Int4             total;
 
1681
  Boolean          added_code_breaks = FALSE;
 
1682
  
 
1683
  if (sfp == NULL || codonStr == NULL)
 
1684
  {
 
1685
    return FALSE;
 
1686
  }
 
1687
 
 
1688
  /* Get the nucleotide sequence */
 
1689
 
 
1690
  dnaLen = SeqLocLen (sfp->location);
 
1691
  if (dnaLen < 1)
 
1692
    return FALSE;
 
1693
 
 
1694
  crp = (CdRegionPtr) sfp->data.value.ptrvalue;
 
1695
 
 
1696
  bases = ReadCodingRegionBases (sfp->location, dnaLen, crp->frame, &total);
 
1697
 
 
1698
  /* Search for the selected codon in the */
 
1699
  /* nucleotide sequence.  If found, add  */
 
1700
  /* it as a codebreak.                   */
 
1701
 
 
1702
  basePtr = bases;
 
1703
  aaPosition = 0;
 
1704
  while (basePtr[0] != '\0') {
 
1705
    if (StringNCmp (basePtr, codonStr, 3) == 0) {
 
1706
 
 
1707
      /* Create a new seq point object with the aa location */
 
1708
 
 
1709
      aaSpp = SeqPntNew ();
 
1710
      aaSpp->point  = aaPosition;
 
1711
      aaSpp->strand = Seq_strand_plus;
 
1712
      aaSpp->id = SeqLocId (sfp->product);
 
1713
      aaSpp->fuzz   = NULL;
 
1714
 
 
1715
      /* Make a SeqLoc using the seq point */
 
1716
 
 
1717
      aaSlp = (SeqLocPtr) ValNodeNew (NULL);
 
1718
      aaSlp->choice = SEQLOC_PNT;
 
1719
      aaSlp->data.ptrvalue = (Pointer) aaSpp;
 
1720
 
 
1721
      /* Convert the seqloc to a DNA location */
 
1722
 
 
1723
      dnaSlp = aaLoc_to_dnaLoc (sfp, aaSlp);
 
1724
 
 
1725
      /* Create the code break using the DNA location */
 
1726
 
 
1727
      cbp = CodeBreakNew ();
 
1728
      cbp->loc = dnaSlp;
 
1729
      sctp = SeqCodeTableFind (Seq_code_ncbieaa);
 
1730
      aaChar = (Uint1) GetSymbolForResidue (sctp, aaNum);
 
1731
      cbp->aa.value.intvalue = aaChar;
 
1732
      cbp->aa.choice = 1; /* ncbieaa */
 
1733
 
 
1734
      /* Insert the code break into the CDS's */
 
1735
      /* existing list of code breaks.        */
 
1736
 
 
1737
      lastCbp = crp->code_break;
 
1738
      if (lastCbp == NULL)
 
1739
      {
 
1740
              crp->code_break = cbp;        
 
1741
      }
 
1742
      else 
 
1743
      {
 
1744
        while (lastCbp->next != NULL)
 
1745
        {
 
1746
          lastCbp = lastCbp->next;          
 
1747
        }
 
1748
              lastCbp->next = cbp;
 
1749
              cbp->next = NULL;
 
1750
      }
 
1751
 
 
1752
      added_code_breaks = TRUE;
 
1753
    }
 
1754
    basePtr += 3;
 
1755
    aaPosition++;
 
1756
  }
 
1757
 
 
1758
  return added_code_breaks;
 
1759
}
 
1760
 
 
1761
/*---------------------------------------------------------------------*/
 
1762
/*                                                                     */
 
1763
/* ApplyCodeBreak_FeatureCallback () -- Called for each CDS feature in */
 
1764
/*                                      a Bioseq.  Checks for any      */
 
1765
/*                                      nucleotide triplets that match */
 
1766
/*                                      the one in the given code      */
 
1767
/*                                      break and sets a code break    */
 
1768
/*                                      for each one that is found.    */
 
1769
/*                                                                     */
 
1770
/*---------------------------------------------------------------------*/
 
1771
 
 
1772
static Boolean LIBCALLBACK ApplyCodeBreak_FeatureCallback (SeqFeatPtr sfp,
 
1773
                                        SeqMgrFeatContextPtr fcontext)
 
1774
{
 
1775
  Int2             aaNum;
 
1776
  CodeBreakFormPtr cbfp;
 
1777
  Char             codonStr [4];
 
1778
  Int2             i;
 
1779
 
 
1780
  cbfp = (CodeBreakFormPtr) fcontext->userdata;
 
1781
 
 
1782
 
 
1783
  /* Get the selected Amino Acid and codon triplet */
 
1784
 
 
1785
  GetTitle (cbfp->codonText, codonStr, sizeof (codonStr));
 
1786
  for (i = 0; i < 3; i++)
 
1787
    codonStr [i] = TO_UPPER (codonStr [i]);
 
1788
 
 
1789
  aaNum = GetValue (cbfp->aminoAcidPopup);
 
1790
  aaNum += 63;
 
1791
 
 
1792
  if (aaNum >= 74)
 
1793
  {
 
1794
        aaNum++;
 
1795
  }
 
1796
  if (aaNum >= 79)
 
1797
  {
 
1798
        aaNum++;
 
1799
  }
 
1800
 
 
1801
  if (ApplyCodeBreakToCDS (sfp, codonStr, aaNum))
 
1802
  {
 
1803
    /* Retranslate the CDS */
 
1804
 
 
1805
    RetranslateOneCDS (sfp, fcontext->entityID, TRUE, FALSE);
 
1806
    
 
1807
  }
 
1808
  
 
1809
  /* Return TRUE to continue on to the next CDS feature */
 
1810
 
 
1811
  return TRUE;
 
1812
}
 
1813
 
 
1814
/*---------------------------------------------------------------------*/
 
1815
/*                                                                     */
 
1816
/* ApplyCodeBreak_BioseqCallback () -- Called by SeqMgrExploreBioseqs  */
 
1817
/*                                     for each Bioseq.  Searches the  */
 
1818
/*                                     Bioseq for CDS features and adds*/
 
1819
/*                                     the given code break to any     */
 
1820
/*                                     found.                          */
 
1821
/*                                                                     */
 
1822
/*---------------------------------------------------------------------*/
 
1823
 
 
1824
static Boolean LIBCALLBACK ApplyCodeBreak_BioseqCallback (BioseqPtr bsp,
 
1825
                                         SeqMgrBioseqContextPtr bcontext)
 
1826
{
 
1827
  Boolean featureFilterArray [SEQFEAT_MAX];
 
1828
 
 
1829
  /* Set up to explore only CDS features */
 
1830
 
 
1831
  MemSet ((Pointer) (featureFilterArray),
 
1832
          (int) FALSE,
 
1833
          SEQFEAT_MAX);
 
1834
 
 
1835
  featureFilterArray[SEQFEAT_CDREGION] = TRUE;
 
1836
 
 
1837
  /* Explore the Bioseq's CDS features, marking the */
 
1838
  /* ones with internal stop codons as pseudo.      */
 
1839
 
 
1840
  SeqMgrExploreFeatures (bsp, bcontext->userdata,
 
1841
                         ApplyCodeBreak_FeatureCallback, NULL,
 
1842
                         featureFilterArray, NULL);
 
1843
 
 
1844
  /* Return TRUE to continue on to the next Bioseq */
 
1845
 
 
1846
  return TRUE;
 
1847
}
 
1848
 
 
1849
/*---------------------------------------------------------------------*/
 
1850
/*                                                                     */
 
1851
/* DoAddCodeBreak_Callback () -- Called when the 'Apply' button is     */
 
1852
/*                               pressed in the "Add Code Break"       */
 
1853
/*                               window.  Adds the entered code break  */
 
1854
/*                               to all CDS features.                  */
 
1855
/*                                                                     */
 
1856
/*---------------------------------------------------------------------*/
 
1857
 
 
1858
static void DoAddCodeBreak_Callback (ButtoN b)
 
1859
{
 
1860
  CodeBreakFormPtr  cbfp;
 
1861
 
 
1862
  cbfp = (CodeBreakFormPtr) GetObjectExtra (b);
 
1863
 
 
1864
  /* Change to the "working" cursor */
 
1865
 
 
1866
  Hide (cbfp->form);
 
1867
  WatchCursor ();
 
1868
  Update ();
 
1869
 
 
1870
  /* Visit all the Bioseqs, where we will */
 
1871
  /* then explore their CDS features.     */
 
1872
 
 
1873
  SeqMgrExploreBioseqs (cbfp->input_entityID, NULL, (Pointer) cbfp,
 
1874
                        ApplyCodeBreak_BioseqCallback, TRUE, FALSE, TRUE);
 
1875
 
 
1876
  /* Restore the cursor and force an update */
 
1877
 
 
1878
  ArrowCursor ();
 
1879
  Update ();
 
1880
  ObjMgrSetDirtyFlag (cbfp->input_entityID, TRUE);
 
1881
  ObjMgrSendMsg (OM_MSG_UPDATE, cbfp->input_entityID, 0, 0);
 
1882
  Remove (cbfp->form);
 
1883
}
 
1884
 
 
1885
/*---------------------------------------------------------------------*/
 
1886
/*                                                                     */
 
1887
/* PopulateAAPopup () -- Creates a popup list of amino acids.          */
 
1888
/*                                                                     */
 
1889
/*     NOTE : This function is identical to (and identically named as) */
 
1890
/*            a function in cdrgn.c                                    */
 
1891
/*                                                                     */
 
1892
/*---------------------------------------------------------------------*/
 
1893
 
 
1894
static void PopulateAAPopup (PopuP AAitem)
 
1895
 
 
1896
{
 
1897
  Char             ch;
 
1898
  Uint1            first;
 
1899
  Uint1            i;
 
1900
  Char             item [77];
 
1901
  Uint1            last;
 
1902
  SeqCodeTablePtr  sctp;
 
1903
  CharPtr          str;
 
1904
 
 
1905
  sctp = SeqCodeTableFind (Seq_code_ncbieaa);
 
1906
  first = FirstResidueInCode (sctp);
 
1907
  last = LastResidueInCode (sctp);
 
1908
  PopupItem (AAitem, " ");
 
1909
  for (i = 65; i <= last; i++) {
 
1910
    if (i == 74 || i == 79) {
 
1911
      continue;
 
1912
    }
 
1913
    ch = GetSymbolForResidue (sctp, i);
 
1914
    str = (CharPtr) GetNameForResidue (sctp, i);
 
1915
    sprintf (item, "%c    %s", ch, str);
 
1916
    PopupItem (AAitem, item);
 
1917
  } 
 
1918
  SetValue (AAitem, 1); 
 
1919
}
 
1920
 
 
1921
/*---------------------------------------------------------------------*/
 
1922
/*                                                                     */
 
1923
/* IsLegalCodon () - Determines if a three base string is a legal      */
 
1924
/*                   codon.                                            */
 
1925
/*                                                                     */
 
1926
/*---------------------------------------------------------------------*/
 
1927
 
 
1928
static Boolean IsLegalCodon (CharPtr codonStr)
 
1929
{
 
1930
  Int2 i;
 
1931
  Char baseChar;
 
1932
 
 
1933
  /* Only allow three characters */
 
1934
 
 
1935
  if (StringLen (codonStr) > 3)
 
1936
    return FALSE;
 
1937
 
 
1938
  /* Allow only the character A,C,G,T,U and */
 
1939
  /* convert the U to a T.                  */
 
1940
 
 
1941
  i = 0;
 
1942
  while (i < 3) {
 
1943
 
 
1944
    if (codonStr [i] == '\0')
 
1945
      break;
 
1946
 
 
1947
    baseChar = codonStr [i];
 
1948
    
 
1949
    if (StringChr ("acgtuACGTU", baseChar) == NULL)
 
1950
      return FALSE;
 
1951
    if ('U' == baseChar)
 
1952
      codonStr [i] = 'T';
 
1953
    else if ('u' == baseChar)
 
1954
      codonStr [i] = 't';
 
1955
    
 
1956
    i++;
 
1957
  }
 
1958
 
 
1959
  /* If we made it this far, it's a valid codon */
 
1960
 
 
1961
  return TRUE;
 
1962
}
 
1963
 
 
1964
/*---------------------------------------------------------------------*/
 
1965
/*                                                                     */
 
1966
/* CodonText_Callback () -- Called whenever a keystoke is entered in   */
 
1967
/*                          Codon text field.  Validates to see if the */
 
1968
/*                          keystroke should be allowed.               */
 
1969
/*                                                                     */
 
1970
/*---------------------------------------------------------------------*/
 
1971
 
 
1972
static void CodonText_Callback (TexT codonText)
 
1973
 
 
1974
{
 
1975
  CodeBreakFormPtr  cbfp;
 
1976
  Int2              aaNum;
 
1977
  Char              newCodonStr [5];
 
1978
 
 
1979
  /* Get the currect code break data */
 
1980
 
 
1981
  cbfp = (CodeBreakFormPtr) GetObjectExtra (codonText);
 
1982
  if (cbfp == NULL)
 
1983
    return;
 
1984
 
 
1985
  /* If the new codon string is not legal */
 
1986
  /* then reset to the previous text.     */
 
1987
 
 
1988
  GetTitle (codonText, newCodonStr, sizeof (newCodonStr));
 
1989
 
 
1990
  if (!IsLegalCodon (newCodonStr))
 
1991
    StringCpy (newCodonStr, cbfp->currentCodonStr);
 
1992
  else
 
1993
    StringCpy (cbfp->currentCodonStr, newCodonStr);
 
1994
 
 
1995
  SafeSetTitle (cbfp->codonText, newCodonStr);
 
1996
 
 
1997
  /* Only enable the accept button if */
 
1998
  /* we have a full codon.            */
 
1999
 
 
2000
  if (StringLen (newCodonStr) != 3) {
 
2001
    SafeDisable (cbfp->acceptButton);
 
2002
    return;
 
2003
  }
 
2004
 
 
2005
  /* See if an amino acid has been selected yet */
 
2006
 
 
2007
  aaNum = GetValue (cbfp->aminoAcidPopup);
 
2008
  if (aaNum <= 1) {
 
2009
    SafeDisable (cbfp->acceptButton);
 
2010
    return;
 
2011
  }
 
2012
 
 
2013
  /* If we made it this far then we have both a codon and */
 
2014
  /* an amino acid, so enable the accept button.          */
 
2015
 
 
2016
  SafeEnable (cbfp->acceptButton);
 
2017
}
 
2018
 
 
2019
/*---------------------------------------------------------------------*/
 
2020
/*                                                                     */
 
2021
/* SelectAminoAcid_Callback () -- Called whenever a new amino acid is  */
 
2022
/*                                selected in the Amino Acid Popup.    */
 
2023
/*                                Toggles 'Accept' button base on      */
 
2024
/*                                current state.                       */
 
2025
/*                                                                     */
 
2026
/*---------------------------------------------------------------------*/
 
2027
 
 
2028
static void SelectAminoAcid_Callback (PopuP p)
 
2029
{
 
2030
  CodeBreakFormPtr  cbfp;
 
2031
  Char              codonStr [4];
 
2032
  Int2              aaNum;
 
2033
 
 
2034
  /* Get the currect code break data */
 
2035
 
 
2036
  cbfp = (CodeBreakFormPtr) GetObjectExtra (p);
 
2037
  if (cbfp == NULL)
 
2038
    return;
 
2039
 
 
2040
  /* Only enable the accept button if */
 
2041
  /* we have a full codon.            */
 
2042
 
 
2043
  GetTitle (cbfp->codonText, codonStr, sizeof (codonStr));
 
2044
  if (StringLen (codonStr) != 3) {
 
2045
    SafeDisable (cbfp->acceptButton);
 
2046
    return;
 
2047
  }
 
2048
 
 
2049
  /* Get the newly selected amino acid */
 
2050
 
 
2051
  aaNum = GetValue (cbfp->aminoAcidPopup);
 
2052
 
 
2053
  /* If an amino acid is selected then */
 
2054
  /* enable the accept button.         */
 
2055
 
 
2056
  if (aaNum > 1)
 
2057
    SafeEnable (cbfp->acceptButton);
 
2058
  else
 
2059
    SafeDisable (cbfp->acceptButton);
 
2060
}
 
2061
 
 
2062
/*---------------------------------------------------------------------*/
 
2063
/*                                                                     */
 
2064
/* AddGlobalCodeBreak () -- Gets a nucleotide triplet and an amino     */
 
2065
/*                          acid from the user and adds them as        */
 
2066
/*                          codebreaks for all CDS features.           */
 
2067
/*                                                                     */
 
2068
/*---------------------------------------------------------------------*/
 
2069
 
 
2070
extern void AddGlobalCodeBreak (IteM i);
 
2071
extern void AddGlobalCodeBreak (IteM i)
 
2072
 
 
2073
{
 
2074
  BaseFormPtr      bfp;
 
2075
  WindoW           breakWin;
 
2076
  GrouP            mainGroup;
 
2077
  GrouP            buttGroup;
 
2078
  CodeBreakFormPtr cbfp;
 
2079
 
 
2080
  /* Get the current state of things */
 
2081
 
 
2082
#ifdef WIN_MAC
 
2083
  bfp = currentFormDataPtr;
 
2084
#else
 
2085
  bfp = GetObjectExtra (i);
 
2086
#endif
 
2087
  if (bfp == NULL)
 
2088
    return;
 
2089
 
 
2090
  cbfp = (CodeBreakFormPtr) MemNew (sizeof (EvidenceFormData));
 
2091
 
 
2092
  /* Create a window to get the codon and */
 
2093
  /* the Amino acid from the user.        */
 
2094
 
 
2095
  breakWin = FixedWindow (-50, -33, -10, -10,
 
2096
                          "Add Code Break", StdCloseWindowProc);
 
2097
  SetObjectExtra (breakWin, cbfp, StdCleanupFormProc);
 
2098
  cbfp->form = (ForM) breakWin;
 
2099
  cbfp->formmessage = NULL;
 
2100
  cbfp->input_entityID = bfp->input_entityID;
 
2101
 
 
2102
  mainGroup = HiddenGroup (breakWin, -2, 0, NULL);
 
2103
 
 
2104
  /* Create a text entry box for the nucl. codon */
 
2105
 
 
2106
  StaticPrompt (mainGroup, "Triplet Codon", 0, popupMenuHeight,
 
2107
                programFont, 'l');
 
2108
  cbfp->codonText = DialogText (mainGroup, "", 3, CodonText_Callback);
 
2109
  SetObjectExtra (cbfp->codonText, cbfp, NULL);
 
2110
  cbfp->currentCodonStr [0] = '\0';
 
2111
 
 
2112
  /* Add a Popup list of Amino Acids */
 
2113
 
 
2114
  StaticPrompt (mainGroup, "Amino Acid", 0, popupMenuHeight,
 
2115
                programFont, 'l');
 
2116
  cbfp->aminoAcidPopup = PopupList (mainGroup, TRUE,
 
2117
                                    SelectAminoAcid_Callback);
 
2118
  PopulateAAPopup (cbfp->aminoAcidPopup);
 
2119
  SetObjectExtra (cbfp->aminoAcidPopup, cbfp, NULL);
 
2120
 
 
2121
  /* Add Accept and Cancel buttons */
 
2122
 
 
2123
  buttGroup = HiddenGroup (breakWin, 2, 0, NULL);
 
2124
  cbfp->acceptButton = DefaultButton (buttGroup, "Accept",
 
2125
                                   DoAddCodeBreak_Callback);
 
2126
  SetObjectExtra (cbfp->acceptButton, cbfp, NULL);
 
2127
  SafeDisable (cbfp->acceptButton);
 
2128
  PushButton (buttGroup, "Cancel", StdCancelButtonProc);
 
2129
 
 
2130
  /* Line things up and display the window */
 
2131
 
 
2132
  AlignObjects (ALIGN_CENTER, (HANDLE) mainGroup, (HANDLE) buttGroup, NULL);
 
2133
  RealizeWindow (breakWin);
 
2134
  Show (breakWin);
 
2135
  Update ();
 
2136
 
 
2137
}
 
2138
 
 
2139
static void ParseCodonQualToCodeBreakCallback (SeqFeatPtr sfp, Pointer userdata)
 
2140
{
 
2141
  SeqCodeTablePtr sctp;
 
2142
  GBQualPtr       gqual, prev_qual = NULL, next_qual;
 
2143
  CharPtr         cp;
 
2144
  Char            codon_text[4];
 
2145
  Char            symbol_text [4];
 
2146
  Int2            aaNum;
 
2147
  Int4            i;
 
2148
  Boolean         converted_qual;
 
2149
  
 
2150
  if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION || userdata == NULL)
 
2151
  {
 
2152
    return;
 
2153
  }
 
2154
  
 
2155
  sctp = (SeqCodeTablePtr) userdata;
 
2156
  
 
2157
  for (gqual = sfp->qual; gqual != NULL; gqual = next_qual)
 
2158
  {
 
2159
    next_qual = gqual->next;
 
2160
    converted_qual = FALSE;
 
2161
    if (StringCmp (gqual->qual, "codon") == 0)
 
2162
    {
 
2163
      cp = StringSearch (gqual->val, "seq:\"");
 
2164
      if (cp != NULL)
 
2165
      {
 
2166
        cp += 5;
 
2167
        StringNCpy (codon_text, cp, 3);
 
2168
        codon_text [3] = 0;
 
2169
        for (i = 0; i < 3; i++)
 
2170
          codon_text [i] = TO_UPPER (codon_text [i]);
 
2171
 
 
2172
        cp = StrChr (cp, ':');
 
2173
        if (cp != NULL)
 
2174
        {
 
2175
          cp++;
 
2176
          StringNCpy (symbol_text, cp, 3);
 
2177
          symbol_text [3] = 0;
 
2178
          aaNum = FindResidueByName (symbol_text, sctp);         
 
2179
          if (ApplyCodeBreakToCDS (sfp, codon_text, aaNum))
 
2180
          {
 
2181
            /* Retranslate the CDS */
 
2182
 
 
2183
            RetranslateOneCDS (sfp, sfp->idx.entityID, TRUE, FALSE);
 
2184
            
 
2185
            /* remove the codon qual */
 
2186
            if (prev_qual == NULL)
 
2187
            {
 
2188
              sfp->qual = gqual->next;
 
2189
            }
 
2190
            else
 
2191
            {
 
2192
              prev_qual->next = gqual->next;
 
2193
            }
 
2194
            gqual->next = NULL;
 
2195
            GBQualFree (gqual);
 
2196
            converted_qual = TRUE;
 
2197
          }
 
2198
        }
 
2199
      }
 
2200
    }
 
2201
    if (!converted_qual)
 
2202
    {
 
2203
      prev_qual = gqual;
 
2204
    }
 
2205
  }
 
2206
}
 
2207
 
 
2208
extern void ParseCodonQualToCodeBreak (IteM i)
 
2209
{
 
2210
  BaseFormPtr      bfp;
 
2211
  SeqEntryPtr      sep;
 
2212
  SeqCodeTablePtr  sctp;
 
2213
  
 
2214
#ifdef WIN_MAC
 
2215
  bfp = currentFormDataPtr;
 
2216
#else
 
2217
  bfp = GetObjectExtra (i);
 
2218
#endif
 
2219
  if (bfp == NULL) return;
 
2220
 
 
2221
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
2222
  if (sep == NULL) return;
 
2223
  
 
2224
  WatchCursor ();
 
2225
  Update ();
 
2226
  
 
2227
  sctp = SeqCodeTableFind (Seq_code_ncbieaa);
 
2228
  
 
2229
  VisitFeaturesInSep (sep, sctp, ParseCodonQualToCodeBreakCallback);
 
2230
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
2231
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
2232
  ArrowCursor ();
 
2233
  Update ();
1212
2234
}
1213
2235
 
1214
2236
static Boolean CorrectGenCodeCallback (GatherContextPtr gcp)
1253
2275
  if (IS_Bioseq_set (sep)) {
1254
2276
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
1255
2277
    if (bssp != NULL && (bssp->_class == 7 ||
1256
 
                         (bssp->_class >= 13 && bssp->_class <= 16))) {
 
2278
                         (IsPopPhyEtcSet (bssp->_class)))) {
1257
2279
      for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
1258
2280
        CorrectGenCodes (sep, entityID);
1259
2281
      }
1808
2830
  Boolean        is_feature;
1809
2831
  LisT           objlist;
1810
2832
  TexT           findthis;
 
2833
  TexT           fromTxt;
 
2834
  TexT           toTxt;
1811
2835
  Uint2          itemtype;
1812
2836
  Uint2          subtype;
1813
 
  ObjMgrPtr      omp;
1814
 
  ObjMgrTypePtr  omtp;
1815
2837
  ValNodePtr     head;
1816
2838
  Boolean        stringfound;
1817
2839
  Char           findStr [128];
 
2840
  Boolean        take_action_when_string_present;
 
2841
  GrouP          string_constraint_type;
 
2842
  ButtoN         case_insensitive;
 
2843
  Int4           from;
 
2844
  Int4           to;
1818
2845
  ValNodePtr     bsplist;
1819
2846
  ValNodePtr     bssplist;
1820
2847
} RemoveFormData, PNTR RemoveFormPtr;
1821
2848
 
1822
 
static void LIBCALLBACK AsnWriteRemoveForDCallBack (AsnExpOptStructPtr pAEOS)
1823
 
 
1824
 
{
1825
 
  CharPtr        pchFind;
1826
 
  CharPtr        pchSource;
1827
 
  RemoveFormPtr  rfp;
1828
 
 
1829
 
  rfp = (RemoveFormPtr) pAEOS->data;
1830
 
  if (ISA_STRINGTYPE (AsnFindBaseIsa (pAEOS->atp))) {
1831
 
        pchSource = (CharPtr) pAEOS->dvp->ptrvalue;
1832
 
        pchFind = rfp->findStr;
1833
 
        if (StringSearch (pchSource, pchFind) != NULL) {
1834
 
          rfp->stringfound = TRUE;
1835
 
        }
1836
 
  }
1837
 
}
1838
 
 
1839
 
static Boolean ObjectHasSubstring (ObjMgrTypePtr omtp, AsnIoPtr aip, Pointer ptr, RemoveFormPtr rfp)
1840
 
 
1841
 
{
1842
 
  rfp->stringfound = FALSE;
1843
 
  (omtp->asnwrite) (ptr, aip, NULL);
1844
 
  return rfp->stringfound;
1845
 
}
1846
 
 
1847
 
static void RemoveFeatureCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
1848
 
 
1849
 
{
1850
 
  AsnExpOptPtr   aeop;
1851
 
  AsnIoPtr       aip;
1852
 
  BioseqPtr      bsp;
1853
 
  BioseqSetPtr   bssp;
1854
 
  SeqAnnotPtr    nextsap;
1855
 
  SeqFeatPtr     nextsfp;
1856
 
  Boolean        notext;
1857
 
  ObjMgrTypePtr  omtp;
1858
 
  Pointer PNTR   prevsap;
1859
 
  Pointer PNTR   prevsfp;
1860
 
  BioseqPtr      productbsp;
1861
 
  BioseqPtr      productcdna;
1862
 
  BioseqSetPtr   productnps;
1863
 
  RemoveFormPtr  rfp;
1864
 
  SeqAnnotPtr    sap;
1865
 
  SeqFeatPtr     sfp;
1866
 
  SeqIdPtr       sip;
1867
 
  Uint2          subtype;
1868
 
 
1869
 
  if (mydata == NULL) return;
1870
 
  if (sep == NULL || sep->data.ptrvalue == NULL) return;
1871
 
  rfp = (RemoveFormPtr) mydata;
1872
 
  if (rfp == NULL) return;
1873
 
  omtp = rfp->omtp;
1874
 
  if (omtp == NULL || omtp->subtypefunc == NULL) return;
1875
 
  if (IS_Bioseq (sep)) {
1876
 
    bsp = (BioseqPtr) sep->data.ptrvalue;
1877
 
    sap = bsp->annot;
1878
 
    prevsap = (Pointer PNTR) &(bsp->annot);
1879
 
  } else if (IS_Bioseq_set (sep)) {
1880
 
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
1881
 
    sap = bssp->annot;
1882
 
    prevsap = (Pointer PNTR) &(bssp->annot);
1883
 
  } else return;
1884
 
  GetTitle (rfp->findthis, rfp->findStr, sizeof (rfp->findStr) - 1);
1885
 
  notext = StringHasNoText (rfp->findStr);
1886
 
  aip = AsnIoNullOpen ();
1887
 
  aeop = AsnExpOptNew (aip, NULL, NULL, AsnWriteRemoveForDCallBack);
1888
 
  if (aeop != NULL) {
1889
 
    aeop->user_data = (Pointer) rfp;
1890
 
  }
1891
 
  while (sap != NULL) {
1892
 
    nextsap = sap->next;
1893
 
    if (sap->type == 1) {
1894
 
      sfp = (SeqFeatPtr) sap->data;
1895
 
      prevsfp = (Pointer PNTR) &(sap->data);
1896
 
      while (sfp != NULL) {
1897
 
        nextsfp = sfp->next;
1898
 
        subtype = (*(omtp->subtypefunc)) ((Pointer) sfp);
1899
 
        if (subtype == rfp->subtype ||
1900
 
           (rfp->subtype == FEATDEF_IMP &&
1901
 
            subtype >= FEATDEF_allele && subtype <= FEATDEF_site_ref)) {
1902
 
          if (notext || ObjectHasSubstring (omtp, aip, (Pointer) sfp, rfp)) {
1903
 
            if (sfp->data.choice == SEQFEAT_CDREGION) {
1904
 
              if (sfp->product != NULL) {
1905
 
                sip = SeqLocId (sfp->product);
1906
 
                if (sip != NULL) {
1907
 
                  productbsp = BioseqFind (sip);
1908
 
                  if (productbsp != NULL) {
1909
 
                    ValNodeAddPointer (&(rfp->bsplist), 0, (Pointer) productbsp);
1910
 
                  }
1911
 
                }
1912
 
              }
1913
 
            } else if (sfp->data.choice == SEQFEAT_RNA) {
1914
 
              if (sfp->product != NULL) {
1915
 
                sip = SeqLocId (sfp->product);
1916
 
                if (sip != NULL) {
1917
 
                  productcdna = BioseqFind (sip);
1918
 
                  if (productcdna != NULL && productcdna->idx.parenttype == OBJ_BIOSEQSET) {
1919
 
                    productnps = (BioseqSetPtr) productcdna->idx.parentptr;
1920
 
                    if (productnps != NULL && productnps->_class == BioseqseqSet_class_nuc_prot) {
1921
 
                      ValNodeAddPointer (&(rfp->bssplist), 0, (Pointer) productnps);
1922
 
                    }
1923
 
                  }
1924
 
                }
1925
 
              }
1926
 
            }
1927
 
            *(prevsfp) = sfp->next;
1928
 
            sfp->next = NULL;
1929
 
            SeqFeatFree (sfp);
1930
 
          } else {
1931
 
            prevsfp = (Pointer PNTR) &(sfp->next);
1932
 
          }
1933
 
        } else {
1934
 
          prevsfp = (Pointer PNTR) &(sfp->next);
1935
 
        }
1936
 
        sfp = nextsfp;
1937
 
      }
1938
 
    }
1939
 
    if (sap->data == NULL) {
1940
 
      *(prevsap) = sap->next;
1941
 
      sap->next = NULL;
1942
 
      SeqAnnotFree (sap);
1943
 
    } else {
1944
 
      prevsap = (Pointer PNTR) &(sap->next);
1945
 
    }
1946
 
    sap = nextsap;
1947
 
  }
1948
 
  AsnIoClose (aip);
1949
 
}
1950
 
 
1951
 
static void RemoveDescriptorCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
1952
 
 
1953
 
{
1954
 
  AsnExpOptPtr   aeop;
1955
 
  AsnIoPtr       aip;
1956
 
  BioseqPtr      bsp;
1957
 
  BioseqSetPtr   bssp;
1958
 
  ValNodePtr     nextsdp;
1959
 
  Boolean        notext;
1960
 
  ObjMgrTypePtr  omtp;
1961
 
  Pointer PNTR   prevsdp;
1962
 
  RemoveFormPtr  rfp;
1963
 
  ValNodePtr     sdp;
1964
 
  Uint2          subtype;
1965
 
 
1966
 
  if (mydata == NULL) return;
1967
 
  if (sep == NULL || sep->data.ptrvalue == NULL) return;
1968
 
  rfp = (RemoveFormPtr) mydata;
1969
 
  if (rfp == NULL) return;
1970
 
  omtp = rfp->omtp;
1971
 
  if (omtp == NULL || omtp->subtypefunc == NULL) return;
1972
 
  if (IS_Bioseq (sep)) {
1973
 
    bsp = (BioseqPtr) sep->data.ptrvalue;
1974
 
    sdp = bsp->descr;
1975
 
    prevsdp = (Pointer PNTR) &(bsp->descr);
1976
 
  } else if (IS_Bioseq_set (sep)) {
1977
 
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
1978
 
    sdp = bssp->descr;
1979
 
    prevsdp = (Pointer PNTR) &(bssp->descr);
1980
 
  } else return;
1981
 
  GetTitle (rfp->findthis, rfp->findStr, sizeof (rfp->findStr) - 1);
1982
 
  notext = StringHasNoText (rfp->findStr);
1983
 
  aip = AsnIoNullOpen ();
1984
 
  aeop = AsnExpOptNew (aip, NULL, NULL, AsnWriteRemoveForDCallBack);
1985
 
  if (aeop != NULL) {
1986
 
    aeop->user_data = (Pointer) rfp;
1987
 
  }
1988
 
  while (sdp != NULL) {
1989
 
    nextsdp = sdp->next;
1990
 
    subtype = (*(omtp->subtypefunc)) ((Pointer) sdp);
1991
 
    if (subtype == rfp->subtype) {
1992
 
      if (notext || ObjectHasSubstring (omtp, aip, (Pointer) sdp, rfp)) {
1993
 
        *(prevsdp) = sdp->next;
1994
 
        sdp->next = NULL;
1995
 
        SeqDescFree (sdp);
1996
 
      } else {
1997
 
        prevsdp = (Pointer PNTR) &(sdp->next);
1998
 
      }
1999
 
    } else {
2000
 
      prevsdp = (Pointer PNTR) &(sdp->next);
2001
 
    }
2002
 
    sdp = nextsdp;
2003
 
  }
2004
 
  AsnIoClose (aip);
 
2849
static Boolean ObjectInRange (SeqFeatPtr sfp, Int4 from, Int4 to)
 
2850
 
 
2851
{
 
2852
  SeqMgrFeatContext  context;
 
2853
 
 
2854
  if (sfp == NULL || from < 0 || to < 0) return TRUE;
 
2855
  if (SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL, 0, 0, sfp, &context) == sfp) {
 
2856
    if (context.left > to) return FALSE;
 
2857
    if (context.right < from) return FALSE;
 
2858
  }
 
2859
  return TRUE;
 
2860
}
 
2861
 
 
2862
 
 
2863
static void RemoveFeatureCallback (SeqFeatPtr sfp, Pointer userdata)
 
2864
{
 
2865
  RemoveFormPtr rfp;
 
2866
  SeqIdPtr      sip;
 
2867
  BioseqPtr     productbsp, productcdna;
 
2868
  BioseqSetPtr  productnps;
 
2869
  
 
2870
  if (sfp == NULL || userdata == NULL) return;
 
2871
 
 
2872
  rfp = (RemoveFormPtr) userdata;
 
2873
  if (rfp == NULL) return;
 
2874
  if (sfp->idx.subtype == rfp->subtype ||
 
2875
      (rfp->subtype == FEATDEF_IMP && IsRealImpFeat (sfp->idx.subtype)) ||
 
2876
      rfp->subtype == ALL_FEATURES) 
 
2877
  {
 
2878
    if ((rfp->from == -1 && rfp->to == -1) || ObjectInRange (sfp, rfp->from, rfp->to)) 
 
2879
    {
 
2880
      if (sfp->data.choice == SEQFEAT_CDREGION) 
 
2881
      {
 
2882
        if (sfp->product != NULL) 
 
2883
        {
 
2884
          sip = SeqLocId (sfp->product);
 
2885
          if (sip != NULL) 
 
2886
          {
 
2887
            productbsp = BioseqFind (sip);
 
2888
            if (productbsp != NULL) 
 
2889
            {
 
2890
              ValNodeAddPointer (&(rfp->bsplist), 0, (Pointer) productbsp);
 
2891
            }
 
2892
          }
 
2893
        }
 
2894
      } 
 
2895
      else if (sfp->data.choice == SEQFEAT_RNA) 
 
2896
      {
 
2897
        if (sfp->product != NULL) 
 
2898
        {
 
2899
          sip = SeqLocId (sfp->product);
 
2900
          if (sip != NULL) 
 
2901
          {
 
2902
            productcdna = BioseqFind (sip);
 
2903
            if (productcdna != NULL && productcdna->idx.parenttype == OBJ_BIOSEQSET) 
 
2904
            {
 
2905
              productnps = (BioseqSetPtr) productcdna->idx.parentptr;
 
2906
              if (productnps != NULL && productnps->_class == BioseqseqSet_class_nuc_prot) 
 
2907
              {
 
2908
                ValNodeAddPointer (&(rfp->bssplist), 0, (Pointer) productnps);
 
2909
              }
 
2910
            }
 
2911
          }
 
2912
        }
 
2913
      }
 
2914
      sfp->idx.deleteme = TRUE;  
 
2915
    }
 
2916
  }
 
2917
}
 
2918
 
 
2919
static void RemoveFeatures (SeqEntryPtr sep, RemoveFormPtr rfp)
 
2920
{
 
2921
  FeaturesWithTextData fd;
 
2922
  Char           str [32];
 
2923
  Int4           swap;
 
2924
  long int       val;
 
2925
  
 
2926
  GetTitle (rfp->findthis, rfp->findStr, sizeof (rfp->findStr) - 1);
 
2927
  fd.search_text = rfp->findStr;
 
2928
  fd.no_text = StringHasNoText (rfp->findStr);
 
2929
  fd.seqFeatChoice = 0;
 
2930
  fd.featDefChoice = 0;
 
2931
  fd.case_insensitive = GetStatus (rfp->case_insensitive);
 
2932
  fd.act_when_string_not_present = ! rfp->take_action_when_string_present;
 
2933
  fd.userdata = rfp;
 
2934
  fd.callback = RemoveFeatureCallback;
 
2935
  GetTitle (rfp->fromTxt, str, sizeof (str) - 1);
 
2936
  if ((! StringHasNoText (str)) && sscanf (str, "%ld", &val) == 1 && val >= 0) {
 
2937
    rfp->from = (Int4) val;
 
2938
  } else {
 
2939
    rfp->from = -1;
 
2940
  }
 
2941
  GetTitle (rfp->toTxt, str, sizeof (str) - 1);
 
2942
  if ((! StringHasNoText (str)) && sscanf (str, "%ld", &val) == 1 && val >= 0) {
 
2943
    rfp->to = (Int4) val;
 
2944
  } else {
 
2945
    rfp->to = -1;
 
2946
  }
 
2947
  if (rfp->from > rfp->to) {
 
2948
    swap = rfp->from;
 
2949
    rfp->from = rfp->to;
 
2950
    rfp->to = swap;
 
2951
  }
 
2952
  OperateOnSeqEntryFeaturesWithText (sep, &fd);
 
2953
  DeleteMarkedObjects (rfp->input_entityID, OBJ_SEQENTRY, (Pointer) sep);
 
2954
}
 
2955
 
 
2956
static void RemoveDescriptorCallback (SeqDescrPtr sdp, Pointer userdata)
 
2957
{
 
2958
  ObjValNodePtr ovp;
 
2959
  RemoveFormPtr rfp;
 
2960
  
 
2961
  if (sdp == NULL || userdata == NULL || sdp->extended == 0) return;
 
2962
  rfp = (RemoveFormPtr) userdata;
 
2963
  if (rfp == NULL) return;
 
2964
  
 
2965
  ovp = (ObjValNodePtr) sdp;
 
2966
    
 
2967
  if (sdp->choice == rfp->subtype) 
 
2968
  {
 
2969
    ovp->idx.deleteme = TRUE;   
 
2970
  }
 
2971
}
 
2972
 
 
2973
static void RemoveDescriptors (SeqEntryPtr sep, RemoveFormPtr rfp)
 
2974
{
 
2975
  DescriptorsWithTextData dd;
 
2976
  Char                    str [32];
 
2977
  Int4                    swap;
 
2978
  long int                val;
 
2979
  
 
2980
  GetTitle (rfp->findthis, rfp->findStr, sizeof (rfp->findStr) - 1);
 
2981
  dd.search_text = rfp->findStr;
 
2982
  dd.no_text = StringHasNoText (rfp->findStr);
 
2983
  dd.case_insensitive = GetStatus (rfp->case_insensitive);
 
2984
  dd.act_when_string_not_present = ! rfp->take_action_when_string_present;
 
2985
  dd.userdata = rfp;
 
2986
  dd.callback = RemoveDescriptorCallback;
 
2987
  GetTitle (rfp->fromTxt, str, sizeof (str) - 1);
 
2988
  if ((! StringHasNoText (str)) && sscanf (str, "%ld", &val) == 1 && val >= 0) {
 
2989
    rfp->from = (Int4) val;
 
2990
  } else {
 
2991
    rfp->from = -1;
 
2992
  }
 
2993
  GetTitle (rfp->toTxt, str, sizeof (str) - 1);
 
2994
  if ((! StringHasNoText (str)) && sscanf (str, "%ld", &val) == 1 && val >= 0) {
 
2995
    rfp->to = (Int4) val;
 
2996
  } else {
 
2997
    rfp->to = -1;
 
2998
  }
 
2999
  if (rfp->from > rfp->to) {
 
3000
    swap = rfp->from;
 
3001
    rfp->from = rfp->to;
 
3002
    rfp->to = swap;
 
3003
  }
 
3004
  OperateOnSeqEntryDescriptorsWithText (sep, &dd);
 
3005
  DeleteMarkedObjects (rfp->input_entityID, OBJ_SEQENTRY, (Pointer) sep);
2005
3006
}
2006
3007
 
2007
3008
static void DoRemoveAsnObject (ButtoN b)
2017
3018
  ValNodePtr     tmp;
2018
3019
  Int2           val;
2019
3020
  ValNodePtr     vnp;
 
3021
  Boolean        removed_some_features;
2020
3022
 
2021
3023
  rfp = GetObjectExtra (b);
2022
3024
  if (rfp == NULL) return;
2030
3032
  } else {
2031
3033
    rfp->itemtype = OBJ_SEQDESC;
2032
3034
  }
2033
 
  vnp = NULL;
2034
 
  val = GetValue (rfp->objlist);
2035
 
  if (val > 0) {
2036
 
    vnp = rfp->head;
2037
 
    while (vnp != NULL && val > 1) {
2038
 
      val--;
2039
 
      vnp = vnp->next;
2040
 
    }
2041
 
  }
2042
 
  if (vnp != NULL) {
2043
 
    rfp->omp = ObjMgrGet ();
2044
 
    rfp->omtp = NULL;
2045
 
    if (rfp->omp != NULL) {
2046
 
      rfp->omtp = ObjMgrTypeFind (rfp->omp, rfp->itemtype, NULL, NULL);
2047
 
    }
2048
 
    rfp->subtype = vnp->choice;
2049
 
    if (rfp->itemtype != 0 && rfp->subtype != 0 && rfp->omtp != NULL) {
2050
 
      if (rfp->is_feature) {
2051
 
        SeqEntryExplore (sep, (Pointer) rfp, RemoveFeatureCallback);
2052
 
        if (rfp->bsplist != NULL) {
2053
 
          ans = Message (MSG_YN, "Remove protein products?");
2054
 
          if (ans == ANS_YES) {
2055
 
            for (tmp = rfp->bsplist; tmp != NULL; tmp = tmp->next) {
2056
 
              bsp = (BioseqPtr) tmp->data.ptrvalue;
2057
 
              itemID = GetItemIDGivenPointer (rfp->input_entityID, OBJ_BIOSEQ, (Pointer) bsp);
2058
 
              if (itemID > 0) {
2059
 
                MemSet ((Pointer) (&ompc), 0, sizeof (OMProcControl));
2060
 
                ompc.do_not_reload_from_cache = TRUE;
2061
 
                ompc.input_entityID = rfp->input_entityID;
2062
 
                ompc.input_itemID = itemID;
2063
 
                ompc.input_itemtype = OBJ_BIOSEQ;
2064
 
                if (! DetachDataForProc (&ompc, FALSE)) {
2065
 
                  Message (MSG_POSTERR, "DetachDataForProc failed");
2066
 
                }
2067
 
              }
2068
 
            }
2069
 
          }
2070
 
        }
2071
 
        if (rfp->bssplist != NULL) {
2072
 
          ans = Message (MSG_YN, "Remove cDNA nuc-prot products?");
2073
 
          if (ans == ANS_YES) {
2074
 
            for (tmp = rfp->bssplist; tmp != NULL; tmp = tmp->next) {
2075
 
              bssp = (BioseqSetPtr) tmp->data.ptrvalue;
2076
 
              itemID = GetItemIDGivenPointer (rfp->input_entityID, OBJ_BIOSEQSET, (Pointer) bssp);
2077
 
              if (itemID > 0) {
2078
 
                MemSet ((Pointer) (&ompc), 0, sizeof (OMProcControl));
2079
 
                ompc.do_not_reload_from_cache = TRUE;
2080
 
                ompc.input_entityID = rfp->input_entityID;
2081
 
                ompc.input_itemID = itemID;
2082
 
                ompc.input_itemtype = OBJ_BIOSEQSET;
2083
 
                if (! DetachDataForProc (&ompc, FALSE)) {
2084
 
                  Message (MSG_POSTERR, "DetachDataForProc failed");
2085
 
                }
2086
 
              }
2087
 
            }
2088
 
          }
2089
 
        }
2090
 
      } else {
2091
 
        SeqEntryExplore (sep, (Pointer) rfp, RemoveDescriptorCallback);
 
3035
 
 
3036
  if (rfp->itemtype == 0) return;
 
3037
 
 
3038
  removed_some_features = FALSE;
 
3039
  
 
3040
  if (GetValue (rfp->string_constraint_type) == 1)
 
3041
  {
 
3042
        rfp->take_action_when_string_present = TRUE;
 
3043
  }
 
3044
  else
 
3045
  {
 
3046
    rfp->take_action_when_string_present = FALSE;
 
3047
  }
 
3048
 
 
3049
  val = 1;
 
3050
  for (vnp = rfp->head; vnp != NULL; vnp = vnp->next)
 
3051
  {
 
3052
    if (GetItemStatus (rfp->objlist, val))
 
3053
    {
 
3054
      rfp->subtype = vnp->choice;
 
3055
      if (rfp->subtype != 0) {
 
3056
        if (rfp->is_feature) {
 
3057
          RemoveFeatures (sep, rfp);
 
3058
          removed_some_features = TRUE;
 
3059
        } else {
 
3060
          RemoveDescriptors (sep, rfp);
 
3061
        }
 
3062
      }
 
3063
    }
 
3064
    val ++;
 
3065
  }
 
3066
 
 
3067
  if (removed_some_features) {
 
3068
    if (rfp->bsplist != NULL) {
 
3069
      ans = Message (MSG_YN, "Remove protein products?");
 
3070
      if (ans == ANS_YES) {
 
3071
        for (tmp = rfp->bsplist; tmp != NULL; tmp = tmp->next) {
 
3072
          bsp = (BioseqPtr) tmp->data.ptrvalue;
 
3073
          itemID = GetItemIDGivenPointer (rfp->input_entityID, OBJ_BIOSEQ, (Pointer) bsp);
 
3074
          if (itemID > 0) {
 
3075
            MemSet ((Pointer) (&ompc), 0, sizeof (OMProcControl));
 
3076
            ompc.do_not_reload_from_cache = TRUE;
 
3077
            ompc.input_entityID = rfp->input_entityID;
 
3078
            ompc.input_itemID = itemID;
 
3079
            ompc.input_itemtype = OBJ_BIOSEQ;
 
3080
            if (! DetachDataForProc (&ompc, FALSE)) {
 
3081
              Message (MSG_POSTERR, "DetachDataForProc failed");
 
3082
            }
 
3083
            SeqMgrDeleteFromBioseqIndex (bsp);
 
3084
          }
 
3085
        }
 
3086
        ans = Message (MSG_YN, "Renormalize Nuc-Prot sets?");
 
3087
        if (ans == ANS_YES)
 
3088
        {
 
3089
          RemoveOrphanProteins (rfp->input_entityID, sep);
 
3090
          RenormalizeNucProtSets (sep, TRUE);           
 
3091
        }
 
3092
      }
 
3093
    }
 
3094
    if (rfp->bssplist != NULL) {
 
3095
      ans = Message (MSG_YN, "Remove cDNA nuc-prot products?");
 
3096
      if (ans == ANS_YES) {
 
3097
        for (tmp = rfp->bssplist; tmp != NULL; tmp = tmp->next) {
 
3098
          bssp = (BioseqSetPtr) tmp->data.ptrvalue;
 
3099
          itemID = GetItemIDGivenPointer (rfp->input_entityID, OBJ_BIOSEQSET, (Pointer) bssp);
 
3100
          if (itemID > 0) {
 
3101
            MemSet ((Pointer) (&ompc), 0, sizeof (OMProcControl));
 
3102
            ompc.do_not_reload_from_cache = TRUE;
 
3103
            ompc.input_entityID = rfp->input_entityID;
 
3104
            ompc.input_itemID = itemID;
 
3105
            ompc.input_itemtype = OBJ_BIOSEQSET;
 
3106
            if (! DetachDataForProc (&ompc, FALSE)) {
 
3107
              Message (MSG_POSTERR, "DetachDataForProc failed");
 
3108
            }
 
3109
          }
 
3110
        }
2092
3111
      }
2093
3112
    }
2094
3113
  }
2100
3119
  Remove (rfp->form);
2101
3120
}
2102
3121
 
 
3122
static void RemoveDefLinesCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
 
3123
 
 
3124
{
 
3125
  BioseqPtr      bsp;
 
3126
  BioseqSetPtr   bssp;
 
3127
  ValNodePtr     nextsdp;
 
3128
  Pointer PNTR   prevsdp;
 
3129
  ValNodePtr     sdp;
 
3130
 
 
3131
  if (sep == NULL || sep->data.ptrvalue == NULL) return;
 
3132
  if (IS_Bioseq (sep)) {
 
3133
    bsp = (BioseqPtr) sep->data.ptrvalue;
 
3134
    sdp = bsp->descr;
 
3135
    prevsdp = (Pointer PNTR) &(bsp->descr);
 
3136
  } else if (IS_Bioseq_set (sep)) {
 
3137
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
 
3138
    sdp = bssp->descr;
 
3139
    prevsdp = (Pointer PNTR) &(bssp->descr);
 
3140
  } else return;
 
3141
 
 
3142
  while (sdp != NULL) {
 
3143
    nextsdp = sdp->next;
 
3144
    if (sdp->choice == Seq_descr_title)
 
3145
    {
 
3146
      *(prevsdp) = sdp->next;
 
3147
      sdp->next = NULL;
 
3148
      SeqDescFree (sdp);
 
3149
    } else {
 
3150
      prevsdp = (Pointer PNTR) &(sdp->next);
 
3151
    }
 
3152
    sdp = nextsdp;
 
3153
  }
 
3154
}
 
3155
 
 
3156
extern void RemoveDefLinesToolBtn (ButtoN b)
 
3157
{
 
3158
  BaseFormPtr  bfp;
 
3159
  SeqEntryPtr  sep;
 
3160
 
 
3161
  bfp = (BaseFormPtr) GetObjectExtra (b);
 
3162
  if (bfp == NULL) return;
 
3163
 
 
3164
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
3165
  if (sep == NULL) return;
 
3166
  
 
3167
  WatchCursor ();
 
3168
  Update ();
 
3169
 
 
3170
  SeqEntryExplore (sep, NULL, RemoveDefLinesCallback);
 
3171
 
 
3172
  ArrowCursor ();
 
3173
  Update ();
 
3174
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
3175
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
3176
  ObjMgrDeSelect (0, 0, 0, 0, NULL);
 
3177
  CommonApplyToAllProc (bfp, ADD_TITLE);
 
3178
}
 
3179
 
2103
3180
int LIBCALLBACK SortByVnpChoice (VoidPtr ptr1, VoidPtr ptr2)
2104
3181
 
2105
3182
{
2153
3230
}
2154
3231
 
2155
3232
static CharPtr descNames [] = {
2156
 
  " ", "MolType", "Modif", "Method", "Name",
2157
 
  "Title", "Organism", "Comment", "Numbering",
 
3233
  " ", " ", " ", " ", "Name",
 
3234
  "Title", " ", "Comment", "Numbering",
2158
3235
  "MapLoc", "PIR", "GenBank", "Publication",
2159
3236
  "Region", "User", "SWISS-PROT", "dbXREF",
2160
3237
  "EMBL", "Create Date", "Update Date", "PRF",
2169
3246
#endif
2170
3247
*/
2171
3248
 
 
3249
CharPtr MostUsedDescriptorList[] = { "Title" };
 
3250
 
 
3251
static Boolean isMostUsedDescriptor (CharPtr descname)
 
3252
{
 
3253
  Int2 i;
 
3254
 
 
3255
  if (descname == NULL) return FALSE;
 
3256
 
 
3257
  for (i=0; i < sizeof (MostUsedDescriptorList) / sizeof (CharPtr); i++)
 
3258
  {
 
3259
    if (StringCmp (descname, MostUsedDescriptorList[i]) == 0)
 
3260
      return TRUE;
 
3261
  }
 
3262
  return FALSE;
 
3263
}
 
3264
 
 
3265
static int LIBCALLBACK SortMostUsedDescriptorsFirst (VoidPtr ptr1, VoidPtr ptr2)
 
3266
 
 
3267
{
 
3268
  ValNodePtr   vnp1;
 
3269
  ValNodePtr   vnp2;
 
3270
  CharPtr      str1;
 
3271
  CharPtr      str2;
 
3272
  Boolean      str1_is_most_used;
 
3273
  Boolean      str2_is_most_used;
 
3274
 
 
3275
  /* Check parameters */
 
3276
 
 
3277
  if ((NULL == ptr1) || (NULL == ptr2))
 
3278
    return 0;
 
3279
 
 
3280
  vnp1 = *((ValNodePtr PNTR) ptr1);
 
3281
  vnp2 = *((ValNodePtr PNTR) ptr2);
 
3282
  if ((NULL == vnp1) || (NULL == vnp2))
 
3283
    return 0;
 
3284
 
 
3285
  str1 = (CharPtr) vnp1->data.ptrvalue;
 
3286
  str2 = (CharPtr) vnp2->data.ptrvalue;
 
3287
  if ((NULL == str1) || (NULL == str2))
 
3288
    return 0;
 
3289
 
 
3290
  str1_is_most_used = isMostUsedDescriptor (str1);
 
3291
  str2_is_most_used = isMostUsedDescriptor (str2);
 
3292
 
 
3293
  if ((str1_is_most_used && str2_is_most_used)
 
3294
    || (!str1_is_most_used && !str2_is_most_used))
 
3295
  {
 
3296
    return SortVnpByString (ptr1, ptr2);
 
3297
  }
 
3298
  else if (str1_is_most_used)
 
3299
  {
 
3300
    return -1;
 
3301
  }
 
3302
  else
 
3303
  {
 
3304
    return 1;
 
3305
  }
 
3306
}
 
3307
 
 
3308
extern ValNodePtr BuildDescriptorValNodeList (void)
 
3309
{
 
3310
  Int4 j;
 
3311
  ValNodePtr vnp;
 
3312
  ValNodePtr head = NULL;
 
3313
  
 
3314
  for (j = 1; descNames [j] != NULL; j++) {
 
3315
    if (StringHasNoText (descNames [j])) continue;
 
3316
    vnp = ValNodeNew (head);
 
3317
    if (head == NULL) {
 
3318
      head = vnp;
 
3319
    }
 
3320
    if (vnp != NULL) {
 
3321
      vnp->choice = j;
 
3322
      vnp->data.ptrvalue = StringSave (descNames [j]);
 
3323
    }
 
3324
  }
 
3325
  head = SortValNode (head, SortMostUsedDescriptorsFirst);
 
3326
  return head;
 
3327
}
 
3328
 
2172
3329
static void RemoveAsnObject (IteM i, Boolean feature)
2173
3330
 
2174
3331
{
2175
3332
  BaseFormPtr        bfp;
2176
3333
  ButtoN             b;
2177
3334
  GrouP              c;
2178
 
  FeatDefPtr         curr;
2179
3335
  GrouP              g;
2180
3336
  GrouP              h;
2181
3337
  ValNodePtr         head;
2182
 
  Int2               j;
2183
3338
  GrouP              k;
2184
 
  Uint1              key;
2185
 
  CharPtr            label = NULL;
2186
3339
  Int2               listHeight;
 
3340
  GrouP              m;
2187
3341
  RemoveFormPtr      rfp;
2188
3342
  SeqEntryPtr        sep;
2189
3343
  StdEditorProcsPtr  sepp;
2190
 
  Char               str [256];
2191
 
  Uint2              subtype;
2192
3344
  CharPtr            title;
2193
3345
  ValNodePtr         vnp;
2194
3346
  WindoW             w;
2238
3390
  } else {
2239
3391
    listHeight = 8;
2240
3392
  }
2241
 
  rfp->objlist = SingleList (g, 16, listHeight, NULL);
 
3393
  rfp->objlist = MultiList (g, 16, listHeight, NULL);
2242
3394
  head = NULL;
2243
3395
  if (feature) {
2244
 
    curr = FeatDefFindNext (NULL, &key, &label, FEATDEF_ANY, TRUE);
2245
 
    while (curr != NULL) {
2246
 
      if (key != FEATDEF_BAD) {
2247
 
        subtype = curr->featdef_key;
2248
 
        vnp = ValNodeNew (head);
2249
 
        if (head == NULL) {
2250
 
          head = vnp;
2251
 
        }
2252
 
        if (vnp != NULL) {
2253
 
          vnp->choice = subtype;
2254
 
          if (subtype != FEATDEF_misc_RNA &&
2255
 
              subtype != FEATDEF_precursor_RNA &&
2256
 
              subtype != FEATDEF_mat_peptide &&
2257
 
              subtype != FEATDEF_sig_peptide &&
2258
 
              subtype != FEATDEF_transit_peptide) {
2259
 
            vnp->data.ptrvalue = StringSave (curr->typelabel);
2260
 
          } else {
2261
 
            StringNCpy_0 (str, curr->typelabel, sizeof (str) - 10);
2262
 
            StringCat (str, "_imp");
2263
 
            vnp->data.ptrvalue = StringSave (str);
2264
 
          }
2265
 
        }
2266
 
      }
2267
 
      curr = FeatDefFindNext (curr, &key, &label, FEATDEF_ANY, TRUE);
2268
 
    }
 
3396
    head = BuildFeatureValNodeList (TRUE, "All", ALL_FEATURES, TRUE, FALSE);
2269
3397
  } else {
2270
 
    for (j = 1; descNames [j] != NULL; j++) {
2271
 
      vnp = ValNodeNew (head);
2272
 
      if (head == NULL) {
2273
 
        head = vnp;
2274
 
      }
2275
 
      if (vnp != NULL) {
2276
 
        vnp->choice = j;
2277
 
        vnp->data.ptrvalue = StringSave (descNames [j]);
2278
 
      }
2279
 
    }
 
3398
    head = BuildDescriptorValNodeList();
2280
3399
  }
2281
3400
  if (head != NULL) {
2282
 
    head = SortValNode (head, SortByVnpChoice);
 
3401
 
2283
3402
    for (vnp = head; vnp != NULL; vnp = vnp->next) {
2284
3403
      ListItem (rfp->objlist, (CharPtr) vnp->data.ptrvalue);
2285
3404
    }
2288
3407
  rfp->bsplist = NULL;
2289
3408
  rfp->bssplist = NULL;
2290
3409
 
2291
 
  k = HiddenGroup (h, 0, 2, NULL);
2292
 
  StaticPrompt (k, "Optional string constraint", 0, dialogTextHeight, programFont, 'c');
 
3410
  k = NormalGroup (h, 0, 3, "Optional string constraint", NULL, NULL);
 
3411
  rfp->string_constraint_type = HiddenGroup (k, 0, 2, NULL);
 
3412
  RadioButton (rfp->string_constraint_type, "Remove when text is present");
 
3413
  RadioButton (rfp->string_constraint_type, "Remove when text is not present");
 
3414
  SetValue (rfp->string_constraint_type, 1);
2293
3415
  rfp->findthis = DialogText (k, "", 14, NULL);
 
3416
  rfp->case_insensitive = CheckBox (k, "Case Insensitive", NULL);
 
3417
 
 
3418
  m = NULL;
 
3419
  if (feature) {
 
3420
    m = HiddenGroup (h, 4, 0, NULL);
 
3421
    StaticPrompt (m, "From", 0, dialogTextHeight, programFont, 'l');
 
3422
    rfp->fromTxt = DialogText (m, "", 6, NULL);
 
3423
    StaticPrompt (m, "To", 0, dialogTextHeight, programFont, 'l');
 
3424
    rfp->toTxt = DialogText (m, "", 6, NULL);
 
3425
  }
2294
3426
 
2295
3427
  c = HiddenGroup (h, 4, 0, NULL);
2296
 
  b = PushButton (c, "Accept", DoRemoveAsnObject);
 
3428
  b = DefaultButton (c, "Accept", DoRemoveAsnObject);
2297
3429
  SetObjectExtra (b, rfp, NULL);
2298
3430
  PushButton (c, "Cancel", StdCancelButtonProc);
2299
3431
 
2300
 
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) k, (HANDLE) c, NULL);
 
3432
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) k, (HANDLE) c, (HANDLE) m, NULL);
2301
3433
  RealizeWindow (w);
2302
3434
  Show (w);
2303
3435
  Update ();
2318
3450
#define SLCT_FEAT    1
2319
3451
#define SLCT_DESC    2
2320
3452
#define SLCT_BIOSEQ  3
 
3453
#define SLCT_PUB     4
2321
3454
 
2322
3455
typedef struct selectformdata {
2323
3456
  FEATURE_FORM_BLOCK
2332
3465
  ValNodePtr     head;
2333
3466
  Boolean        stringfound;
2334
3467
  Char           findStr [128];
 
3468
  ButtoN         when_string_not_present;
 
3469
  ButtoN         case_insensitive;
2335
3470
} SelectFormData, PNTR SelectFormPtr;
2336
3471
 
2337
 
static Boolean SelectObjCallback (GatherContextPtr gcp)
2338
 
 
2339
 
{
2340
 
  ObjMgrTypePtr  omtp;
2341
 
  SelectFormPtr  selfp;
2342
 
  Uint2          subtype;
2343
 
 
2344
 
  if (gcp == NULL) return TRUE;
2345
 
  selfp = (SelectFormPtr) gcp->userdata;
2346
 
  if (selfp == NULL) return TRUE;
2347
 
  if (gcp->thistype != selfp->itemtype) return TRUE;
2348
 
  omtp = selfp->omtp;
2349
 
  if (omtp == NULL) return TRUE;
2350
 
  subtype = (*(omtp->subtypefunc)) ((Pointer) gcp->thisitem);
2351
 
  if (subtype != selfp->subtype) return TRUE;
2352
 
  ObjMgrAlsoSelect (gcp->entityID, gcp->itemID, gcp->thistype, 0, NULL);
2353
 
  return TRUE;
2354
 
}
 
3472
static void FeatureSelectCallback (SeqFeatPtr sfp, Pointer userdata)
 
3473
{
 
3474
  Uint1Ptr subtype;
 
3475
  if (sfp == NULL) return;
 
3476
  
 
3477
  if (userdata != NULL)
 
3478
  {
 
3479
        subtype = (Uint1Ptr) userdata;
 
3480
        if (*subtype != sfp->idx.subtype) return;
 
3481
  }
 
3482
  ObjMgrAlsoSelect (sfp->idx.entityID, sfp->idx.itemID, OBJ_SEQFEAT, 0, NULL);
 
3483
}
 
3484
 
 
3485
static void DescriptorSelectCallback (SeqDescrPtr sdp, Pointer userdata)
 
3486
{
 
3487
  ObjValNodePtr ovp;
 
3488
  Uint1Ptr subtype;
 
3489
  
 
3490
  if (sdp == NULL || sdp->extended == 0) return;
 
3491
  
 
3492
  ovp = (ObjValNodePtr) sdp;
 
3493
  if (userdata != NULL)
 
3494
  {
 
3495
        subtype = (Uint1Ptr) userdata;
 
3496
        if (*subtype != ovp->idx.subtype) return;
 
3497
  }
 
3498
    
 
3499
  ObjMgrAlsoSelect (ovp->idx.entityID, ovp->idx.itemID, OBJ_SEQDESC, 0, NULL);
 
3500
}
 
3501
 
 
3502
static void BioseqSelectCallback (BioseqPtr bsp, Pointer userdata)
 
3503
{
 
3504
  Uint1Ptr subtype;
 
3505
  
 
3506
  if (bsp == NULL) return;
 
3507
  
 
3508
  if (userdata != NULL)
 
3509
  {
 
3510
        subtype = (Uint1Ptr) userdata;
 
3511
        if (*subtype != bsp->idx.subtype) return;
 
3512
  }
 
3513
    
 
3514
  ObjMgrAlsoSelect (bsp->idx.entityID, bsp->idx.itemID, bsp->idx.itemtype, 0, NULL);
 
3515
}
 
3516
 
2355
3517
 
2356
3518
static void DoSelectAsnObject (ButtoN b)
2357
3519
 
2358
3520
{
2359
 
  GatherScope    gs;
2360
 
  SelectFormPtr  selfp;
2361
 
  SeqEntryPtr    sep;
2362
 
  Int2           val;
2363
 
  ValNodePtr     vnp;
 
3521
  SelectFormPtr           selfp;
 
3522
  SeqEntryPtr             sep;
 
3523
  Int2                    val;
 
3524
  ValNodePtr              vnp;
 
3525
  FeaturesWithTextData    fd;
 
3526
  DescriptorsWithTextData dd;
 
3527
  Uint1                   bioseq_choice = Seq_repr_raw;
 
3528
  Uint1                   pub_choice = FEATDEF_PUB;
2364
3529
 
2365
3530
  selfp = GetObjectExtra (b);
2366
3531
  if (selfp == NULL) return;
2367
3532
  sep = GetTopSeqEntryForEntityID (selfp->input_entityID);
2368
3533
  if (sep == NULL) return;
2369
3534
  Hide (selfp->form);
 
3535
  
 
3536
  vnp = NULL;
 
3537
  if (selfp->type == SLCT_FEAT || selfp->type == SLCT_DESC)
 
3538
  {
 
3539
    val = GetValue (selfp->objlist);
 
3540
    if (val > 0) {
 
3541
      vnp = selfp->head;
 
3542
      while (vnp != NULL && val > 1) {
 
3543
        val--;
 
3544
        vnp = vnp->next;
 
3545
      }
 
3546
    }
 
3547
  }
 
3548
 
2370
3549
  switch (selfp->type) {
2371
3550
    case SLCT_FEAT :
2372
 
      selfp->itemtype = OBJ_SEQFEAT;
 
3551
      GetTitle (selfp->findthis, selfp->findStr, sizeof (selfp->findStr) - 1);
 
3552
      fd.search_text = selfp->findStr;
 
3553
      fd.no_text = StringHasNoText (selfp->findStr);
 
3554
      fd.seqFeatChoice = 0;
 
3555
      fd.featDefChoice = 0;
 
3556
      fd.case_insensitive = GetStatus (selfp->case_insensitive);
 
3557
      fd.act_when_string_not_present = GetStatus (selfp->when_string_not_present);
 
3558
      fd.callback = FeatureSelectCallback;
 
3559
      if (vnp == NULL)
 
3560
      {
 
3561
        fd.userdata = NULL;
 
3562
      }
 
3563
      else
 
3564
      {
 
3565
        fd.userdata = (Pointer) &(vnp->choice);
 
3566
      }
 
3567
      OperateOnSeqEntryFeaturesWithText (sep, &fd);     
2373
3568
      break;
2374
3569
    case SLCT_DESC :
2375
 
      selfp->itemtype = OBJ_SEQDESC;
 
3570
      GetTitle (selfp->findthis, selfp->findStr, sizeof (selfp->findStr) - 1);
 
3571
      dd.search_text = selfp->findStr;
 
3572
      dd.no_text = StringHasNoText (selfp->findStr);
 
3573
      dd.case_insensitive = GetStatus (selfp->case_insensitive);
 
3574
      dd.act_when_string_not_present = GetStatus (selfp->when_string_not_present);
 
3575
      dd.callback = DescriptorSelectCallback;
 
3576
      if (vnp == NULL)
 
3577
      {
 
3578
        fd.userdata = NULL;
 
3579
      }
 
3580
      else
 
3581
      {
 
3582
        fd.userdata = (Pointer) &(vnp->choice);
 
3583
      }
 
3584
      OperateOnSeqEntryDescriptorsWithText (sep, &dd);  
2376
3585
      break;
2377
3586
    case SLCT_BIOSEQ :
2378
 
      selfp->itemtype = OBJ_BIOSEQ;
 
3587
          VisitBioseqsInSep (sep, (Pointer) &bioseq_choice, BioseqSelectCallback);      
2379
3588
      break;
 
3589
        case SLCT_PUB:
 
3590
      GetTitle (selfp->findthis, selfp->findStr, sizeof (selfp->findStr) - 1);
 
3591
      fd.search_text = selfp->findStr;
 
3592
      fd.no_text = StringHasNoText (selfp->findStr);
 
3593
      fd.seqFeatChoice = 0;
 
3594
      fd.featDefChoice = 0;
 
3595
      fd.case_insensitive = GetStatus (selfp->case_insensitive);
 
3596
      fd.act_when_string_not_present = GetStatus (selfp->when_string_not_present);
 
3597
      fd.callback = FeatureSelectCallback;
 
3598
      fd.userdata = (Pointer) &pub_choice;
 
3599
      OperateOnSeqEntryFeaturesWithText (sep, &fd); 
 
3600
      dd.search_text = fd.search_text;
 
3601
      dd.no_text = fd.no_text;
 
3602
      dd.case_insensitive = fd.case_insensitive;
 
3603
      dd.act_when_string_not_present = fd.act_when_string_not_present;
 
3604
      dd.callback = DescriptorSelectCallback;
 
3605
      dd.userdata = fd.userdata;        
 
3606
      OperateOnSeqEntryDescriptorsWithText (sep, &dd);  
 
3607
      break;    
2380
3608
    default :
2381
3609
      Remove (selfp->form);
2382
3610
      Update ();
2384
3612
  }
2385
3613
  WatchCursor ();
2386
3614
  Update ();
2387
 
  vnp = NULL;
2388
 
  val = GetValue (selfp->objlist);
2389
 
  if (val > 0) {
2390
 
    vnp = selfp->head;
2391
 
    while (vnp != NULL && val > 1) {
2392
 
      val--;
2393
 
      vnp = vnp->next;
2394
 
    }
2395
 
  }
2396
 
  if (selfp->type == SLCT_BIOSEQ || vnp != NULL) {
2397
 
    selfp->omp = ObjMgrGet ();
2398
 
    selfp->omtp = NULL;
2399
 
    if (selfp->omp != NULL) {
2400
 
      selfp->omtp = ObjMgrTypeFind (selfp->omp, selfp->itemtype, NULL, NULL);
2401
 
    }
2402
 
    if (selfp->type == SLCT_BIOSEQ) {
2403
 
      selfp->subtype = Seq_repr_raw;
2404
 
    } else {
2405
 
      selfp->subtype = vnp->choice;
2406
 
    }
2407
 
    if (selfp->itemtype != 0 && selfp->subtype != 0 && selfp->omtp != NULL) {
2408
 
      MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
2409
 
      gs.seglevels = 1;
2410
 
      MemSet((Pointer)(gs.ignore), (int)(TRUE), (size_t)(OBJ_MAX * sizeof(Boolean)));
2411
 
      gs.ignore[OBJ_BIOSEQ] = FALSE;
2412
 
      gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
2413
 
      gs.ignore[OBJ_SEQANNOT] = FALSE;
2414
 
      gs.ignore[OBJ_SEQFEAT] = FALSE;
2415
 
      gs.ignore[OBJ_SEQDESC] = FALSE;
2416
 
      GatherEntity (selfp->input_entityID, (Pointer) selfp, SelectObjCallback, &gs);
2417
 
    }
2418
 
  }
 
3615
 
2419
3616
  ArrowCursor ();
2420
3617
  Update ();
2421
3618
  /* ObjMgrSendMsg (OM_MSG_UPDATE, selfp->input_entityID, 0, 0); */
2453
3650
  BaseFormPtr        bfp;
2454
3651
  ButtoN             b;
2455
3652
  GrouP              c;
2456
 
  FeatDefPtr         curr;
2457
3653
  GrouP              g;
2458
3654
  GrouP              h;
 
3655
  GrouP              k, m;
2459
3656
  ValNodePtr         head;
2460
3657
  Int2               j;
2461
 
  Uint1              key;
2462
 
  CharPtr            label = NULL;
2463
3658
  Int2               listHeight;
2464
3659
  SelectFormPtr      selfp;
2465
3660
  SeqEntryPtr        sep;
2466
3661
  StdEditorProcsPtr  sepp;
2467
 
  Uint2              subtype;
2468
3662
  CharPtr            title;
2469
3663
  ValNodePtr         vnp;
2470
3664
  WindoW             w;
2489
3683
    case SLCT_BIOSEQ :
2490
3684
      title = "Sequence Selection";
2491
3685
      break;
 
3686
        case SLCT_PUB:
 
3687
          title = "Publication Selection";
 
3688
          break;
2492
3689
    default :
2493
3690
      title = "? Selection";
2494
3691
      break;
2523
3720
    case SLCT_BIOSEQ :
2524
3721
      StaticPrompt (g, "Sequence", 0, 0, programFont, 'c');
2525
3722
      break;
 
3723
        case SLCT_PUB:
 
3724
          StaticPrompt (g, "Publication", 0, 0, programFont, 'c');
 
3725
          break;
2526
3726
    default :
2527
3727
      break;
2528
3728
  }
2531
3731
  } else {
2532
3732
    listHeight = 8;
2533
3733
  }
2534
 
  selfp->objlist = SingleList (g, 16, listHeight, NULL);
 
3734
  
 
3735
  if (type != SLCT_PUB)
 
3736
  {
 
3737
    selfp->objlist = SingleList (g, 16, listHeight, NULL);
 
3738
  }
2535
3739
  head = NULL;
2536
3740
  if (type == SLCT_FEAT) {
2537
 
    curr = FeatDefFindNext (NULL, &key, &label, FEATDEF_ANY, TRUE);
2538
 
    while (curr != NULL) {
2539
 
      if (key != FEATDEF_BAD) {
2540
 
        subtype = curr->featdef_key;
2541
 
        vnp = ValNodeNew (head);
2542
 
        if (head == NULL) {
2543
 
          head = vnp;
2544
 
        }
2545
 
        if (vnp != NULL) {
2546
 
          vnp->choice = subtype;
2547
 
          vnp->data.ptrvalue = StringSave (curr->typelabel);
2548
 
        }
2549
 
      }
2550
 
      curr = FeatDefFindNext (curr, &key, &label, FEATDEF_ANY, TRUE);
2551
 
    }
 
3741
    head = BuildFeatureValNodeList (TRUE, NULL, ALL_FEATURES, TRUE, FALSE);
2552
3742
  } else if (type == SLCT_DESC) {
2553
3743
    for (j = 1; descNames [j] != NULL; j++) {
 
3744
      if (StringHasNoText (descNames [j])) continue;
2554
3745
      vnp = ValNodeNew (head);
2555
3746
      if (head == NULL) {
2556
3747
        head = vnp;
2562
3753
    }
2563
3754
  }
2564
3755
  if (head != NULL) {
2565
 
    head = SortValNode (head, SortByVnpChoice);
 
3756
    if (type != SLCT_FEAT) {
 
3757
      head = SortValNode (head, SortByVnpChoice);
 
3758
    }
2566
3759
    for (vnp = head; vnp != NULL; vnp = vnp->next) {
2567
3760
      ListItem (selfp->objlist, (CharPtr) vnp->data.ptrvalue);
2568
3761
    }
2569
3762
  }
2570
3763
  selfp->head = head;
2571
3764
 
 
3765
  if (selfp->type == SLCT_FEAT || selfp->type == SLCT_DESC || selfp->type == SLCT_PUB)
 
3766
  {
 
3767
    k = HiddenGroup (h, 0, 3, NULL);
 
3768
    StaticPrompt (k, "Optional string constraint", 0, dialogTextHeight, programFont, 'c');
 
3769
    selfp->findthis = DialogText (k, "", 14, NULL);
 
3770
    m = HiddenGroup (k, 2, 0, NULL);
 
3771
    selfp->case_insensitive = CheckBox (m, "Case Insensitive", NULL);
 
3772
    selfp->when_string_not_present = CheckBox (m, "When String Not Present", NULL);
 
3773
  }
 
3774
 
2572
3775
  c = HiddenGroup (h, 4, 0, NULL);
2573
 
  b = PushButton (c, "Accept", DoSelectAsnObject);
 
3776
  b = DefaultButton (c, "Accept", DoSelectAsnObject);
2574
3777
  SetObjectExtra (b, selfp, NULL);
2575
3778
  PushButton (c, "Cancel", StdCancelButtonProc);
2576
3779
 
2577
 
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
 
3780
  if (selfp->type == SLCT_FEAT || selfp->type == SLCT_DESC)
 
3781
  {
 
3782
    AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) k, (HANDLE) c, NULL);
 
3783
  }
 
3784
  else
 
3785
  {
 
3786
    AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
 
3787
  }
2578
3788
  RealizeWindow (w);
2579
3789
  if (type == SLCT_BIOSEQ) {
2580
3790
    DoSelectAsnObject (b);
2603
3813
  SelectAsnObject (i, SLCT_BIOSEQ);
2604
3814
}
2605
3815
 
 
3816
extern void SelectPubs (IteM i)
 
3817
 
 
3818
{
 
3819
  SelectAsnObject (i, SLCT_PUB);
 
3820
}
 
3821
 
2606
3822
typedef struct fuseformdata {
2607
3823
  FEATURE_FORM_BLOCK
2608
3824
 
2647
3863
        subtype = (*(omtp->subtypefunc)) ((Pointer) sfp);
2648
3864
        if (subtype == ffp->subtype ||
2649
3865
           (ffp->subtype == FEATDEF_IMP &&
2650
 
            subtype >= FEATDEF_allele && subtype <= FEATDEF_site_ref)) {
 
3866
            IsRealImpFeat (subtype))) {
2651
3867
          if (first != NULL) {
2652
3868
            target = GetBioseqGivenSeqLoc (sfp->location, ffp->input_entityID);
2653
3869
            if (target != NULL) {
2806
4022
          subtype != FEATDEF_precursor_RNA &&
2807
4023
          subtype != FEATDEF_mat_peptide &&
2808
4024
          subtype != FEATDEF_sig_peptide &&
2809
 
          subtype != FEATDEF_transit_peptide) {
 
4025
          subtype != FEATDEF_transit_peptide &&
 
4026
          subtype != FEATDEF_Imp_CDS) {
2810
4027
        vnp = ValNodeNew (head);
2811
4028
        if (head == NULL) {
2812
4029
          head = vnp;
2828
4045
  ffp->head = head;
2829
4046
 
2830
4047
  c = HiddenGroup (h, 4, 0, NULL);
2831
 
  b = PushButton (c, "Accept", DoFuseFeature);
 
4048
  b = DefaultButton (c, "Accept", DoFuseFeature);
2832
4049
  SetObjectExtra (b, ffp, NULL);
2833
4050
  PushButton (c, "Cancel", StdCancelButtonProc);
2834
4051
 
2852
4069
  DIALOG_MESSAGE_BLOCK
2853
4070
  GrouP         status;
2854
4071
  TexT          curator;
 
4072
  TexT          source;
 
4073
  Int2          indexer;
2855
4074
  DialoG        fields;
2856
4075
} RefgeneUserDialog, PNTR RefgeneUserDialogPtr;
2857
4076
 
2912
4131
  ValNodePtr    head;
2913
4132
  Int2          i;
2914
4133
  Int2          j;
 
4134
  CharPtr       name;
2915
4135
  ObjectIdPtr   oip;
2916
4136
  Boolean       seqChange;
2917
4137
  CharPtr       str;
2939
4159
        while (entry != NULL && entry->choice == 11) {
2940
4160
          accession = NULL;
2941
4161
          comment = NULL;
 
4162
          name = NULL;
2942
4163
          gi = 0;
2943
4164
          from = 0;
2944
4165
          to = 0;
2962
4183
                annotChange = ufp->data.boolvalue;
2963
4184
              } else if (StringICmp (oip->str, "comment") == 0 && ufp->choice == 1) {
2964
4185
                comment = (CharPtr) ufp->data.ptrvalue;
 
4186
              } else if (StringICmp (oip->str, "name") == 0 && ufp->choice == 1) {
 
4187
                name = (CharPtr) ufp->data.ptrvalue;
2965
4188
              }
2966
4189
            }
2967
4190
            ufp = ufp->next;
2989
4212
            if (vnp != NULL) {
2990
4213
              vnp->data.ptrvalue = StringSave (str);
2991
4214
            }
 
4215
          } else if (name != NULL) {
 
4216
            sprintf (str, "\t\t%s\t0\t%d\n", name, (int) field);
 
4217
            vnp = ValNodeNew (head);
 
4218
            if (head == NULL) {
 
4219
              head = vnp;
 
4220
            }
 
4221
            if (vnp != NULL) {
 
4222
              vnp->data.ptrvalue = StringSave (str);
 
4223
            }
2992
4224
          }
2993
4225
          entry = entry->next;
2994
4226
        }
3040
4272
  }
3041
4273
  if (curr != NULL && curr->choice == 1) {
3042
4274
    str = (CharPtr) curr->data.ptrvalue;
3043
 
    if (StringICmp (str, "Predicted") == 0) {
 
4275
    if (StringICmp (str, "Inferred") == 0) {
3044
4276
      status = 1;
 
4277
    } else if (StringICmp (str, "Predicted") == 0) {
 
4278
      status = 2;
3045
4279
    } else if (StringICmp (str, "Provisional") == 0) {
3046
 
      status = 2;
 
4280
      status = 3;
3047
4281
    } else if (StringICmp (str, "Validated") == 0) {
3048
 
      status = 3;
 
4282
      status = 4;
3049
4283
    } else if (StringICmp (str, "Reviewed") == 0) {
3050
 
      status = 4;
 
4284
      status = 5;
 
4285
    } else if (StringICmp (str, "Model") == 0) {
 
4286
      status = 6;
 
4287
    } else if (StringICmp (str, "WGS") == 0) {
 
4288
      status = 7;
3051
4289
    }
3052
4290
  }
3053
4291
  for (curr = uop->data; curr != NULL; curr = curr->next) {
3060
4298
    str = (CharPtr) curr->data.ptrvalue;
3061
4299
    SetTitle (rdp->curator, str);
3062
4300
  }
 
4301
  for (curr = uop->data; curr != NULL; curr = curr->next) {
 
4302
    oip = curr->label;
 
4303
    if (oip != NULL && StringICmp (oip->str, "GenomicSource") == 0) {
 
4304
      break;
 
4305
    }
 
4306
  }
 
4307
  if (curr != NULL && curr->choice == 1) {
 
4308
    str = (CharPtr) curr->data.ptrvalue;
 
4309
    SetTitle (rdp->source, str);
 
4310
  }
3063
4311
  SetValue (rdp->status, status);
 
4312
  for (curr = uop->data; curr != NULL; curr = curr->next) {
 
4313
    oip = curr->label;
 
4314
    if (oip != NULL && StringICmp (oip->str, "Indexer") == 0) {
 
4315
      break;
 
4316
    }
 
4317
  }
 
4318
  if (curr != NULL && curr->choice == 2) {
 
4319
    rdp->indexer = (Int2) curr->data.intvalue;
 
4320
  }
 
4321
}
 
4322
 
 
4323
static void AddIndexerToRefGeneTrackUserObject (UserObjectPtr uop, Int2 indexer)
 
4324
 
 
4325
{
 
4326
  UserFieldPtr  curr;
 
4327
  ObjectIdPtr   oip;
 
4328
 
 
4329
  if (uop == NULL || indexer < 1) return;
 
4330
  oip = uop->type;
 
4331
  if (oip == NULL || StringICmp (oip->str, "RefGeneTracking") != 0) return;
 
4332
 
 
4333
  for (curr = uop->data; curr != NULL; curr = curr->next) {
 
4334
    oip = curr->label;
 
4335
    if (oip != NULL && StringICmp (oip->str, "Indexer") == 0) {
 
4336
      break;
 
4337
    }
 
4338
  }
 
4339
 
 
4340
  if (curr == NULL) {
 
4341
    curr = UserFieldNew ();
 
4342
    oip = ObjectIdNew ();
 
4343
    oip->str = StringSave ("Indexer");
 
4344
    curr->label = oip;
 
4345
    curr->choice = 2; /* integer */
 
4346
 
 
4347
    /* link indexer at beginning of list */
 
4348
 
 
4349
    curr->next = uop->data;
 
4350
    uop->data = curr;
 
4351
  }
 
4352
 
 
4353
  if (curr == NULL || curr->choice != 2) return;
 
4354
 
 
4355
  /* replace any existing indexer indication */
 
4356
 
 
4357
  curr->data.intvalue = (Int4) indexer;
3064
4358
}
3065
4359
 
3066
4360
static Pointer RefGeneDialogToUserObjectPtr (DialoG d)
3074
4368
  size_t                len;
3075
4369
  Int4                  num [5];
3076
4370
  Boolean               okay;
3077
 
  CharPtr               organism = NULL;
3078
4371
  RefgeneUserDialogPtr  rdp;
3079
4372
  Boolean               seqChange;
 
4373
  Char                  source [64];
3080
4374
  Int2                  status;
3081
4375
  CharPtr               str;
3082
4376
  TagListPtr            tlp;
3093
4387
 
3094
4388
  status = GetValue (rdp->status);
3095
4389
  if (status == 1) {
 
4390
    AddStatusToRefGeneTrackUserObject (uop, "Inferred");
 
4391
  } else if (status == 2) {
3096
4392
    AddStatusToRefGeneTrackUserObject (uop, "Predicted");
3097
 
  } else if (status == 2) {
 
4393
  } else if (status == 3) {
3098
4394
    AddStatusToRefGeneTrackUserObject (uop, "Provisional");
3099
 
  } else if (status == 3) {
 
4395
  } else if (status == 4) {
3100
4396
    AddStatusToRefGeneTrackUserObject (uop, "Validated");
3101
 
  } else if (status == 4) {
 
4397
  } else if (status == 5) {
3102
4398
    AddStatusToRefGeneTrackUserObject (uop, "Reviewed");
 
4399
  } else if (status == 6) {
 
4400
    AddStatusToRefGeneTrackUserObject (uop, "Model");
 
4401
  } else if (status == 7) {
 
4402
    AddStatusToRefGeneTrackUserObject (uop, "WGS");
 
4403
  }
 
4404
 
 
4405
  GetTitle (rdp->source, source, sizeof (source));
 
4406
  if (! StringHasNoText (source)) {
 
4407
    AddSourceToRefGeneTrackUserObject (uop, source);
3103
4408
  }
3104
4409
 
3105
4410
  GetTitle (rdp->curator, curator, sizeof (curator));
3107
4412
    AddCuratorToRefGeneTrackUserObject (uop, curator);
3108
4413
  }
3109
4414
 
 
4415
  if (rdp->indexer > 0) {
 
4416
    AddIndexerToRefGeneTrackUserObject (uop, rdp->indexer);
 
4417
  }
 
4418
 
3110
4419
  tlp = (TagListPtr) GetObjectExtra (rdp->fields);
3111
4420
  if (tlp != NULL && tlp->vnp != NULL) {
3112
4421
    for (vnp = tlp->vnp; vnp != NULL; vnp = vnp->next) {
3148
4457
                                                  txt [0], num [1],
3149
4458
                                                  seqChange, annotChange,
3150
4459
                                                  txt [2]);
3151
 
          }
3152
 
          for (j = 0; j < 5; j++) {
3153
 
            txt [j] = MemFree (txt [j]);
3154
 
          }
 
4460
          } else if (! StringHasNoText (txt [2])) {
 
4461
            /* comment by itself goes into name */
 
4462
            AddAccessionToRefGeneTrackUserObject (uop, refgene_labels [i],
 
4463
                                                  NULL, num [1],
 
4464
                                                  seqChange, annotChange,
 
4465
                                                  txt [2]);
 
4466
          }
 
4467
        }
 
4468
        for (j = 0; j < 5; j++) {
 
4469
          txt [j] = MemFree (txt [j]);
3155
4470
        }
3156
4471
      }
3157
4472
    }
3186
4501
 
3187
4502
  x = HiddenGroup (p, 4, 0, NULL);
3188
4503
  /* StaticPrompt (x, "Status", 0, stdLineHeight, programFont, 'l'); */
3189
 
  rdp->status = HiddenGroup (x, 4, 0, NULL);
 
4504
  rdp->status = HiddenGroup (x, 7, 0, NULL);
3190
4505
  SetObjectExtra (rdp->status, rdp, NULL);
 
4506
  RadioButton (rdp->status, "Inferred");
3191
4507
  RadioButton (rdp->status, "Predicted");
3192
4508
  RadioButton (rdp->status, "Provisional");
3193
4509
  RadioButton (rdp->status, "Validated");
3194
4510
  RadioButton (rdp->status, "Reviewed");
 
4511
  RadioButton (rdp->status, "Model");
 
4512
  RadioButton (rdp->status, "WGS");
3195
4513
 
3196
 
  y = HiddenGroup (p, 2, 0, NULL);
 
4514
  y = HiddenGroup (p, 4, 0, NULL);
3197
4515
  StaticPrompt (y, "Curator", 0, dialogTextHeight, programFont, 'l');
3198
4516
  rdp->curator = DialogText (y, "", 14, NULL);
 
4517
  StaticPrompt (y, "Genomic Source", 0, dialogTextHeight, programFont, 'l');
 
4518
  rdp->source = DialogText (y, "", 7, NULL);
 
4519
 
 
4520
  rdp->indexer = 0;
3199
4521
 
3200
4522
  q = HiddenGroup (p, -6, 0, NULL);
3201
4523
  lastppt = NULL;
3287
4609
    rfp->data = CreateRefGeneDialog (g);
3288
4610
 
3289
4611
    c = HiddenGroup (w, 2, 0, NULL);
3290
 
    b = PushButton (c, "Accept", StdAcceptFormButtonProc);
 
4612
    b = DefaultButton (c, "Accept", StdAcceptFormButtonProc);
3291
4613
    SetObjectExtra (b, rfp, NULL);
3292
4614
    PushButton (c, "Cancel", StdCancelButtonProc);
3293
4615
    AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
3405
4727
}
3406
4728
*/
3407
4729
 
 
4730
#define CKA_GAPLEN  50 /* max allowed unaligned gap size */
 
4731
 
3408
4732
typedef struct cka_acc {
3409
4733
   CharPtr      accession;
3410
4734
   SeqIdPtr     sip_whole;
3418
4742
   struct cka_acc PNTR next;
3419
4743
} CKA_Acc, PNTR CKA_AccPtr;
3420
4744
 
 
4745
static Int4     CKA_blast_wordsize;
 
4746
static FloatHi  CKA_blast_expect_value;
 
4747
static Boolean  CKA_blast_allow_repeats;
 
4748
static Int4     CKA_blast_detailed_wordsize;
 
4749
static FloatHi  CKA_blast_detailed_expect_value;
 
4750
static Boolean  CKA_blast_detailed_allow_repeats;
 
4751
 
3421
4752
static SeqAlignPtr CKA_MakeAlign(BioseqPtr bsp, CKA_AccPtr acc_head);
3422
4753
 
 
4754
static Boolean SPI_GetAccessionFromSeqId(SeqIdPtr sip, Int4Ptr gi, CharPtr PNTR id)
 
4755
{
 
4756
   Boolean numeric_id_type = FALSE;
 
4757
   Int2 id_len;
 
4758
   GiimPtr gip;
 
4759
   ObjectIdPtr oip;
 
4760
   TextSeqIdPtr textsip;
 
4761
   DbtagPtr dbtag;
 
4762
   PatentSeqIdPtr psip;
 
4763
   PDBSeqIdPtr pdbsip;
 
4764
 
 
4765
   *id = NULL;
 
4766
   *gi = 0;
 
4767
 
 
4768
   switch (sip->choice) {
 
4769
   case SEQID_GI: case SEQID_GIBBSQ: case SEQID_GIBBMT:
 
4770
      *gi = sip->data.intvalue;
 
4771
      numeric_id_type = TRUE;
 
4772
      break;
 
4773
   case SEQID_GIIM:
 
4774
      gip = (GiimPtr) sip->data.ptrvalue;
 
4775
      *gi = gip->id;
 
4776
      numeric_id_type = TRUE;
 
4777
      break;
 
4778
   case SEQID_LOCAL:
 
4779
      oip = (ObjectIdPtr) sip->data.ptrvalue;
 
4780
 
 
4781
      if (oip->str) {
 
4782
         id_len = StringLen(oip->str);
 
4783
         *id = (CharPtr) MemNew(id_len+1);
 
4784
         sprintf(*id, "%s", oip->str);
 
4785
      } else {
 
4786
         *id = (CharPtr) MemNew(6);
 
4787
         sprintf(*id, "%d", oip->id);
 
4788
      }
 
4789
      break;
 
4790
   case SEQID_GENBANK: case SEQID_EMBL: case SEQID_PIR: case SEQID_TPG: case SEQID_TPE: case SEQID_TPD:
 
4791
   case SEQID_SWISSPROT: case SEQID_DDBJ: case SEQID_PRF:
 
4792
   case SEQID_OTHER:
 
4793
      textsip = (TextSeqIdPtr)sip->data.ptrvalue;
 
4794
      id_len = StringLen(textsip->accession);
 
4795
      *id = (CharPtr) MemNew(id_len+1);
 
4796
      if (textsip->version > 0)
 
4797
         sprintf(*id, "%s.%d", textsip->accession, textsip->version);
 
4798
      else
 
4799
         sprintf(*id, "%s", textsip->accession);
 
4800
      break;
 
4801
   case SEQID_GENERAL:
 
4802
      dbtag = (DbtagPtr) sip->data.ptrvalue;
 
4803
      if (dbtag->tag->str == NULL) {
 
4804
         numeric_id_type = TRUE;
 
4805
         *gi = dbtag->tag->id;
 
4806
      } else {
 
4807
         id_len = StringLen(dbtag->tag->str);
 
4808
         *id = (CharPtr) MemNew(id_len+1);
 
4809
         sprintf(*id, "%s", dbtag->tag->str);
 
4810
      }
 
4811
      break;
 
4812
   case SEQID_PATENT:
 
4813
      psip = (PatentSeqIdPtr) sip->data.ptrvalue;
 
4814
      *gi = (Int4) psip->seqid;
 
4815
      numeric_id_type = TRUE;
 
4816
      break;
 
4817
   case SEQID_PDB:
 
4818
      pdbsip = (PDBSeqIdPtr) sip->data.ptrvalue;
 
4819
      id_len = StringLen(pdbsip->mol);
 
4820
      *id = (CharPtr) MemNew(id_len+4);
 
4821
      sprintf(*id, "%s%d", pdbsip->mol, pdbsip->chain);
 
4822
      break;
 
4823
   default: break;
 
4824
   }
 
4825
 
 
4826
   return numeric_id_type;
 
4827
}
 
4828
 
3423
4829
static void CKA_FindAllTpaDescr(SeqEntryPtr sep, Pointer data, Int4 index, Int2 indent)
3424
4830
{
3425
4831
   CKA_AccPtr         acc;
3453
4859
               for (curr = uop->data; curr != NULL; curr = curr->next)
3454
4860
               {
3455
4861
                  if (curr->choice != 11) continue;
3456
 
                  for (ufp = curr->data.ptrvalue; ufp != NULL; ufp = ufp->next)
3457
 
                  {
3458
 
                     if (ufp->choice != 1) continue;
3459
 
                     oip = ufp->label;
3460
 
                     if (oip == NULL || StringICmp (oip->str, "accession") != 0) continue;
3461
 
                     acc = (CKA_AccPtr)MemNew(sizeof(CKA_Acc));
3462
 
                     acc->accession = StringSave((CharPtr)ufp->data.ptrvalue);
3463
 
                     acc->sip_whole = SeqIdDup(bsp->id);
3464
 
                     if (acc_prev == NULL)
3465
 
                        *acc_head = acc_prev = acc;
3466
 
                     else
3467
 
                     {
3468
 
                        acc_prev->next = acc;
3469
 
                        acc_prev = acc;
3470
 
                     }
 
4862
                  
 
4863
                  acc = (CKA_AccPtr)MemNew(sizeof(CKA_Acc));
 
4864
                  acc->sip_whole = SeqIdSetDup(bsp->id);
 
4865
                  /* will use these to mark the span for blast2seq */
 
4866
                  acc->start_acc = acc->stop_acc = -1;
 
4867
                  if (acc_prev == NULL)
 
4868
                    *acc_head = acc_prev = acc;
 
4869
                  else {
 
4870
                    acc_prev->next = acc;
 
4871
                    acc_prev = acc;
 
4872
                  }
 
4873
                  
 
4874
                  for (ufp = curr->data.ptrvalue; ufp != NULL; ufp = ufp->next) {
 
4875
                    oip = ufp->label;
 
4876
                    if (oip == NULL) continue;
 
4877
                    if (StringICmp (oip->str, "accession") == 0 && ufp->choice == 1) {
 
4878
                      acc->accession = StringSave((CharPtr)ufp->data.ptrvalue);
 
4879
                    } else if (StringICmp (oip->str, "from") == 0 && ufp->choice == 2) {
 
4880
                      acc->start_acc = (Int4) ufp->data.intvalue;
 
4881
                    } else if (StringICmp (oip->str, "to") == 0 && ufp->choice == 2) {
 
4882
                      acc->stop_acc = (Int4) ufp->data.intvalue;
 
4883
                    }
3471
4884
                  }
3472
4885
               }
3473
4886
            }
3483
4896
 
3484
4897
   acc1 = *((CKA_AccPtr PNTR)ptr1);
3485
4898
   acc2 = *((CKA_AccPtr PNTR)ptr2);
3486
 
   if (acc1->num < acc2->num)
3487
 
      return -1;
3488
 
   else if (acc1->num > acc2->num)
 
4899
   if (acc1->start_seq < acc2->start_seq)
 
4900
      return -1;
 
4901
   else if (acc1->start_seq > acc2->start_seq)
 
4902
      return 1;
 
4903
   else if (acc1->stop_seq < acc2->stop_seq)
 
4904
      return -1;
 
4905
   else if (acc1->stop_seq > acc2->stop_seq)
3489
4906
      return 1;
3490
4907
   else
3491
4908
      return 0; /* no alignment */
3492
4909
}
3493
4910
 
 
4911
static SeqIdPtr SqnSeqIdFindBestAccession (SeqIdPtr sip)
 
4912
{
 
4913
        Uint1 order[NUM_SEQID];
 
4914
 
 
4915
        if (sip == NULL)
 
4916
                return NULL;
 
4917
        SeqIdBestRank(order, NUM_SEQID);
 
4918
        order[SEQID_GI]=order[SEQID_LOCAL]+2;
 
4919
        order[SEQID_PATENT]=order[SEQID_LOCAL]+1;
 
4920
        return SeqIdSelect (sip, order, NUM_SEQID);
 
4921
}
 
4922
 
3494
4923
static Boolean CKA_ValidateSeqAlign(SeqAlignPtr sap, CKA_AccPtr acc_head, Int4 bioseqlen)
3495
4924
{
3496
4925
   CKA_AccPtr        acc;
3497
4926
   CKA_AccPtr        PNTR accarray;
3498
4927
   AMAlignIndex2Ptr  amaip;
3499
 
   Int4              first;
 
4928
   Int4              first, first_align;
3500
4929
   Boolean           found;
 
4930
   Int4              gi;
3501
4931
   Int4              i;
3502
4932
   Int4              j;
3503
 
  Int4              last;
 
4933
   Int4              k;
 
4934
   Int4              last;
 
4935
   Int4              longest;
 
4936
   Int4              max;
 
4937
   Int4              n;
 
4938
   FILE              PNTR ofp;
3504
4939
   Int4              prev;
 
4940
   Boolean           retval;
 
4941
   Char              string[300];
 
4942
   CharPtr           textid;
 
4943
   Char              textid2[42];
3505
4944
 
3506
4945
   if (sap == NULL || sap->saip == NULL || sap->saip->indextype != INDEX_PARENT)
3507
4946
      return FALSE;
3514
4953
      {
3515
4954
         if (amaip->saps[i] == acc->sap)
3516
4955
            found = TRUE;
3517
 
         else
 
4956
         if (!found)
3518
4957
            acc = acc->next;
3519
4958
      }
3520
4959
      if (!found) /* big error */
3521
 
      {
3522
 
         Message(MSG_ERROR, "Serious error. Please contact sequindev.");
3523
4960
         return FALSE;
3524
 
      }
3525
4961
      acc->num = i+1;
3526
4962
      AlnMgr2GetNthSeqRangeInSA(amaip->saps[i], 1, &acc->start_seq, &acc->stop_seq);
3527
4963
      AlnMgr2GetNthSeqRangeInSA(amaip->saps[i], 2, &acc->start_acc, &acc->stop_acc);
3528
4964
      acc->strand = AlnMgr2GetNthStrand(amaip->saps[i], 2);
 
4965
      acc->start_seq++;
 
4966
      acc->stop_seq++;
 
4967
      acc->start_acc++;
 
4968
      acc->stop_acc++;
3529
4969
   }
3530
4970
   acc = acc_head;
3531
4971
   i = 0;
3532
4972
   while (acc != NULL)
3533
4973
   {
 
4974
      if (acc->start_seq == 0 && acc->stop_seq == 0)
 
4975
      {
 
4976
         AlnMgr2GetNthSeqRangeInSA(acc->sap, 1, &acc->start_seq, &acc->stop_seq);
 
4977
         AlnMgr2GetNthSeqRangeInSA(acc->sap, 2, &acc->start_acc, &acc->stop_acc);
 
4978
         acc->strand = AlnMgr2GetNthStrand(acc->sap, 2);
 
4979
         acc->start_seq++;
 
4980
         acc->stop_seq++;
 
4981
         acc->start_acc++;
 
4982
         acc->stop_acc++;
 
4983
      }
3534
4984
      if (acc->num == 0)
3535
4985
         acc->num = amaip->numsaps; /* sort these guys all to the end */
3536
4986
      i++;
3546
4996
      acc = acc->next;
3547
4997
   }
3548
4998
   HeapSort(accarray, i, sizeof(CKA_AccPtr), CKA_SortAccs);
 
4999
   n=0;
 
5000
   while (accarray[n]->sap == NULL && n < i)
 
5001
   {
 
5002
      n++;
 
5003
   }
 
5004
   SPI_GetAccessionFromSeqId(SqnSeqIdFindBestAccession(accarray[0]->sip_whole), &gi, &textid);
 
5005
   if (textid == NULL)
 
5006
   {
 
5007
      sprintf(textid2, "%d", gi);
 
5008
      textid = textid2;
 
5009
   }
3549
5010
   first = last = -1;
3550
5011
   prev = -1;
3551
 
   for (j=0; j<i && first <=0 ; j++)
 
5012
   retval = TRUE;
 
5013
   for (j=0; j<i /*&& first <=0*/ ; j++)
3552
5014
   {
3553
5015
      acc = accarray[j];
3554
5016
      if (acc->sap != NULL)
3555
5017
      {
3556
 
         if (first == -1)
3557
 
            first = acc->start_seq;
3558
 
         last = MAX(last, acc->stop_seq);
3559
 
      } else
3560
 
         Message (MSG_OKC, "Accession %s does not align to the bioseq.", acc->accession);
 
5018
        if (first == -1) {
 
5019
          first = acc->start_seq;
 
5020
          first_align = j;
 
5021
        }
 
5022
        last = MAX(last, acc->stop_seq);
 
5023
      } else {
 
5024
        continue;
 
5025
      }
3561
5026
      if (prev != -1)
3562
5027
      {
3563
 
         if (acc->start_seq > prev)
3564
 
         {
3565
 
            Message (MSG_ERROR, "The annotated accessions do not completely cover the bioseq:\n %s aligns to %d-%d but next aln is %s to %d-%d", accarray[j-1]->accession, accarray[j-1]->start_seq, accarray[j-1]->stop_seq, acc->accession, acc->start_seq, acc->stop_seq);
3566
 
            MemFree(accarray);
3567
 
            return FALSE;
 
5028
         if (acc->start_seq > prev + CKA_GAPLEN)
 
5029
         {
 
5030
            sprintf(string, "Primary accessions do not completely cover the bioseq %s:\n %s aligns to %d-%d but next aln is %s to %d-%d", textid, accarray[j-1]->accession, accarray[j-1]->start_seq, accarray[j-1]->stop_seq, acc->accession, acc->start_seq, acc->stop_seq);
 
5031
            ofp = FileOpen("cka_validate.txt", "a");
 
5032
            fprintf(ofp, "%s", string);
 
5033
            FileClose(ofp);
 
5034
            Message(MSG_ERROR, "The following message was written to cka_validate.txt: %s", string);
 
5035
            retval = FALSE;
 
5036
         } else if (acc->start_seq > prev)
 
5037
         {
 
5038
            sprintf(string, "Primary accessions do not completely cover the bioseq %s:\n %s aligns to %d-%d but the next aln is %s to %d-%d;\n the gap is less than %d and is acceptable.", textid, accarray[j-1]->accession, accarray[j-1]->start_seq, accarray[j-1]->stop_seq, acc->accession, acc->start_seq, acc->stop_seq, CKA_GAPLEN);
 
5039
            ofp = FileOpen("cka_validate.txt", "a");
 
5040
            fprintf(ofp, "%s", string);
 
5041
            FileClose(ofp);
 
5042
            Message(MSG_ERROR, "The following message was written to cka_validate.txt: %s", string);
 
5043
            retval = FALSE;
3568
5044
         }
3569
5045
      }
3570
5046
      prev = acc->stop_seq+1;
3571
5047
   }
3572
 
   if (first != 0 || last != bioseqlen-1)
 
5048
   if (first != 1 || last != bioseqlen)
3573
5049
   {
3574
 
      if (first != 0)
3575
 
         Message (MSG_ERROR, "The annotated accessions do not completely cover the bioseq:\n %s (the first aln) starts at position %d", accarray[0]->accession, accarray[0]->start_seq);
3576
 
      if (accarray[i-1]->stop_seq != bioseqlen-1)
3577
 
         Message (MSG_ERROR, "The annotated accessions do not completely cover the bioseq:\n %s (the last aln) goes to %d, bioseq length is %d", accarray[i-1]->accession, accarray[i-1]->stop_seq, bioseqlen-1);
 
5050
      if (first > CKA_GAPLEN)
 
5051
      {
 
5052
         sprintf(string, "Primary accessions do not completely cover the bioseq %s:\n %s (the first aln) starts at position %d", textid, accarray[first_align]->accession, accarray[first_align]->start_seq);
 
5053
         ofp = FileOpen("cka_validate.txt", "a");
 
5054
         fprintf(ofp, "%s\n", string);
 
5055
         FileClose(ofp);
 
5056
         Message(MSG_ERROR, "The following message was written to cka_validate.txt: %s", string);
 
5057
         retval = FALSE;
 
5058
      } else if (first != 1)
 
5059
      {
 
5060
         Message(MSG_OK, "Primary accessions do not completely cover the bioseq %s:\n %s (the first alignment) starts at position %d, but the gap is less than %d and is acceptable.", textid, accarray[first_align]->accession, accarray[first_align]->start_seq, CKA_GAPLEN);
 
5061
      }
 
5062
      max = 0;
 
5063
      for (k=0; k<i; k++)
 
5064
      {
 
5065
         if (accarray[k]->stop_seq > max)
 
5066
         {
 
5067
            max = accarray[k]->stop_seq;
 
5068
            longest = k;
 
5069
         }
 
5070
      }
 
5071
      if (accarray[longest]->stop_seq < bioseqlen-CKA_GAPLEN)
 
5072
      {
 
5073
         sprintf (string, "Primary accessions do not completely cover the bioseq %s:\n %s (the last aln) goes to %d, bioseq length is %d", textid, accarray[longest]->accession, accarray[longest]->stop_seq, bioseqlen);
 
5074
         ofp = FileOpen("cka_validate.txt", "a");
 
5075
         fprintf(ofp, "%s", string);
 
5076
         FileClose(ofp);
 
5077
         Message(MSG_ERROR, "The following message was written to cka_validate.txt: %s", string);
 
5078
         retval = FALSE;
 
5079
      } else if (accarray[longest]->stop_seq < bioseqlen)
 
5080
      {
 
5081
         Message(MSG_OK, "Primary accessions do not completely cover the bioseq %s:\n %s (the last alignment) goes to %d, bioseq length is %d, but the gap is less than %d and is acceptable", textid, accarray[longest]->accession, accarray[longest]->stop_seq, bioseqlen, CKA_GAPLEN);
 
5082
      }
3578
5083
      MemFree(accarray);
3579
 
      return FALSE;
 
5084
      accarray = NULL;
3580
5085
   }
3581
5086
   MemFree(accarray);
3582
 
   return TRUE;
 
5087
   return retval;
 
5088
}
 
5089
 
 
5090
static void FrameVwr (
 
5091
  VieweR vwr,
 
5092
  SegmenT pict
 
5093
)
 
5094
 
 
5095
{
 
5096
  RecT  r;
 
5097
 
 
5098
  ResetClip ();
 
5099
  ObjectRect (vwr, &r);
 
5100
  FrameRect (&r);
 
5101
}
 
5102
 
 
5103
static void CKA_ShowAln(SeqAlignPtr sap, CKA_AccPtr acc_head)
 
5104
{
 
5105
   CKA_AccPtr   acc;
 
5106
   BioseqPtr    bsp;
 
5107
   DenseSegPtr  dsp;
 
5108
   Boolean      found;
 
5109
   GrouP        g;
 
5110
   Int4         gi;
 
5111
   Int4         i;
 
5112
   Int4         len;
 
5113
   Int4         numsaps;
 
5114
   SegmenT      picture;
 
5115
   SeqAlignPtr  salp;
 
5116
   SeqIdPtr     sip;
 
5117
   Int4         start;
 
5118
   Int4         start_r;
 
5119
   Int4         stop;
 
5120
   Int4         stop_r;
 
5121
   Char         tmp[42];
 
5122
   CharPtr      textid;
 
5123
   Char         textid2[42];
 
5124
   VieweR       v;
 
5125
   WindoW       w;
 
5126
 
 
5127
   w = FixedWindow(-1, -1, -1, -1, "TPA display", StdCloseWindowProc);
 
5128
   g = HiddenGroup(w, 1, 0, NULL);
 
5129
   v = CreateViewer(g, 750, 300, TRUE, TRUE);
 
5130
   picture = CreatePicture();
 
5131
   salp = (SeqAlignPtr)(sap->segs);
 
5132
   numsaps = 0;
 
5133
   while (salp != NULL)
 
5134
   {
 
5135
      numsaps++;
 
5136
      salp = salp->next;
 
5137
   }
 
5138
   salp = (SeqAlignPtr)(sap->segs);
 
5139
   numsaps++;
 
5140
   dsp = (DenseSegPtr)(salp->segs);
 
5141
   sip = dsp->ids;
 
5142
   SPI_GetAccessionFromSeqId(SqnSeqIdFindBestAccession(sip), &gi, &textid);
 
5143
   if (textid == NULL)
 
5144
   {
 
5145
      sprintf(textid2, "%d", gi);
 
5146
      textid = textid2;
 
5147
   }
 
5148
   bsp = BioseqLockById(sip);
 
5149
   len = bsp->length;
 
5150
   AddRectangle(picture, 0, numsaps*10, (bsp->length*680)/len, numsaps*10-7, 0, TRUE, 0);
 
5151
   sprintf(tmp, "1");
 
5152
   AddLabel(picture, 0-10, numsaps*10-3, tmp, 0, 0, MIDDLE_LEFT, 0);
 
5153
   sprintf(tmp, "%d  %s", bsp->length, textid);
 
5154
   AddLabel(picture, ((bsp->length+10)*680)/len, numsaps*10-3, tmp, 0, 0, MIDDLE_RIGHT, 0);
 
5155
   BioseqUnlock(bsp);
 
5156
   i = numsaps-1;
 
5157
   while (salp != NULL)
 
5158
   {
 
5159
      acc = acc_head;
 
5160
      found = FALSE;
 
5161
      while (acc != NULL && !found)
 
5162
      {
 
5163
         if (acc->sap == salp)
 
5164
            found = TRUE;
 
5165
         else
 
5166
            acc = acc->next;
 
5167
      }
 
5168
      AlnMgr2GetNthSeqRangeInSA(salp, 1, &start, &stop);
 
5169
      start_r = (start*680)/len;
 
5170
      stop_r = (stop*680)/len;
 
5171
      AddRectangle(picture, start_r, i*10, stop_r, i*10-7, 0, TRUE, 0);
 
5172
      dsp = (DenseSegPtr)(salp->segs);
 
5173
      sprintf(tmp, "%d", start+1);
 
5174
      AddLabel(picture, start_r-10, i*10-3, tmp, 0, 0, MIDDLE_LEFT, 0);
 
5175
      sprintf(tmp, "%d  %s", stop+1, acc->accession);
 
5176
      AddLabel(picture, stop_r+10, i*10-3, tmp, 0, 0, MIDDLE_RIGHT, 0);
 
5177
      salp = salp->next;
 
5178
      i--;
 
5179
   }
 
5180
   AttachPicture(v, picture, 0, 0, UPPER_LEFT, 1, 1, FrameVwr);
 
5181
   Show(w);
3583
5182
}
3584
5183
 
3585
5184
static void CKA_RunChecker(SeqEntryPtr sep)
3586
5185
{
 
5186
   CKA_AccPtr   acc;
3587
5187
   CKA_AccPtr   acc_head;
3588
5188
   CKA_AccPtr   acc_head_next;
3589
5189
   CKA_AccPtr   acc_head_prev;
 
5190
   CKA_AccPtr   acc_head_real;
3590
5191
   CKA_AccPtr   acc_head_tmp;
3591
5192
   BioseqPtr    bsp;
3592
5193
   Boolean      found;
 
5194
   Int4         gi;
3593
5195
   SeqIdPtr     lastid;
3594
5196
   SeqAlignPtr  sap;
3595
5197
   SeqHistPtr   shp;
 
5198
   CharPtr      textid;
 
5199
   Char         textid2[42];
3596
5200
 
3597
5201
   if (sep == NULL)
3598
5202
   {
3600
5204
      return;
3601
5205
   }
3602
5206
   acc_head = NULL;
3603
 
   SeqMgrIndexFeatures(0, (Pointer)(sep));
3604
5207
   SeqEntryExplore(sep, &acc_head, CKA_FindAllTpaDescr);
3605
5208
   lastid = NULL;
3606
5209
   if (acc_head == NULL)
3608
5211
      Message(MSG_ERROR, "No Tpa features found in SeqEntry.");
3609
5212
      return;
3610
5213
   }
3611
 
   acc_head_tmp = acc_head;
3612
 
   acc_head_prev = NULL;
 
5214
   acc_head_real = acc_head;
3613
5215
   while (acc_head != NULL)
3614
5216
   {
3615
5217
      lastid = acc_head->sip_whole;
3632
5234
      if (ISA_na(bsp->mol))
3633
5235
      {
3634
5236
         sap = CKA_MakeAlign(bsp, acc_head);
3635
 
         if (CKA_ValidateSeqAlign(sap, acc_head, bsp->length))
3636
 
         {
3637
 
         /* make seq-hist and add it to record */
3638
 
            if (bsp->hist != NULL)
3639
 
            {
3640
 
               shp = bsp->hist;
3641
 
               if (shp->assembly != NULL)
3642
 
                  SeqAlignSetFree(shp->assembly);
3643
 
               shp->assembly = sap;
3644
 
            } else
3645
 
            {
3646
 
               shp = SeqHistNew();
3647
 
               shp->assembly = sap;
3648
 
               bsp->hist = shp;
3649
 
            }
3650
 
         } else
3651
 
            SeqAlignSetFree(sap);
3652
 
      } else
3653
 
         Message(MSG_ERROR, "%s is annotated on a non-nucleotide bioseq.", acc_head->accession);
3654
 
      while (acc_head != NULL)
3655
 
      {
3656
 
         acc_head_tmp = acc_head->next;
3657
 
         acc_head->next = NULL;
3658
 
         MemFree(acc_head->accession);
3659
 
         SeqIdFree(acc_head->sip_whole);
3660
 
         MemFree(acc_head);
3661
 
         acc_head = acc_head_tmp;
3662
 
      }
3663
 
      acc_head = acc_head_next;
3664
 
   }
 
5237
         acc = acc_head;
 
5238
         while (acc != NULL && acc->sap == NULL)
 
5239
         {
 
5240
            acc = acc->next;
 
5241
         }
 
5242
         SPI_GetAccessionFromSeqId(SqnSeqIdFindBestAccession(acc_head->sip_whole), &gi, &textid);
 
5243
         if (textid == NULL)
 
5244
         {
 
5245
            sprintf(textid2, "%d", gi);
 
5246
            textid = textid2;
 
5247
         }
 
5248
 
 
5249
         /* report each accession that does not align to the bioseq */
 
5250
         acc = acc_head;
 
5251
         while (acc != NULL) {
 
5252
           if (acc->sap == NULL) {
 
5253
             Message (MSG_OK, "Accession %s does not align to the bioseq %s.", acc->accession, textid);
 
5254
           }
 
5255
           acc = acc->next;
 
5256
         }
 
5257
 
 
5258
         if (CKA_ValidateSeqAlign(sap, acc_head, bsp->length))
 
5259
            Message(MSG_OK, "Alignments were successfully created and are being added to %s.", textid);
 
5260
         else if (sap != NULL)
 
5261
            Message(MSG_OK, "Alignments were created but are not valid. They are being added to %s for review.", textid);
 
5262
         else if (sap == NULL) {
 
5263
            Message(MSG_ERROR, "No alignments could be created for %s.", textid);
 
5264
            acc_head = acc_head_next;
 
5265
            continue;
 
5266
         }
 
5267
         AlnMgr2IndexLite(sap);
 
5268
         AlnMgr2SortAlnSetByNthRowPos(sap, 1);
 
5269
         /* make seq-hist and add it to record */
 
5270
         if (bsp->hist != NULL)
 
5271
         {
 
5272
            shp = bsp->hist;
 
5273
            if (shp->assembly != NULL)
 
5274
               SeqAlignSetFree(shp->assembly);
 
5275
            shp->assembly = (SeqAlignPtr)(sap->segs);
 
5276
         } else
 
5277
         {
 
5278
            shp = SeqHistNew();
 
5279
            shp->assembly = (SeqAlignPtr)(sap->segs);
 
5280
            bsp->hist = shp;
 
5281
         }
 
5282
         sap->segs = NULL;
 
5283
         SeqAlignFree(sap);
 
5284
             } else
 
5285
         Message(MSG_ERROR, "%s is annotated on a non-nucleotide bioseq.", acc_head->accession);
 
5286
    /* while (acc_head != NULL)
 
5287
     {
 
5288
        acc_head_tmp = acc_head->next;
 
5289
        acc_head->next = NULL;
 
5290
        MemFree(acc_head->accession);
 
5291
        SeqIdFree(acc_head->sip_whole);
 
5292
        MemFree(acc_head);
 
5293
        acc_head = acc_head_tmp;
 
5294
     }*/
 
5295
     acc_head = acc_head_next;
 
5296
  }
 
5297
  /*CKA_ShowAln(sap, acc_head_real);*/
 
5298
  while (acc_head_real != NULL)
 
5299
  {
 
5300
     acc_head_tmp = acc_head_real->next;
 
5301
     MemFree(acc_head_real->accession);
 
5302
     SeqIdFree(acc_head_real->sip_whole);
 
5303
     MemFree(acc_head_real);
 
5304
     acc_head_real = acc_head_tmp;
 
5305
  }
3665
5306
}
3666
5307
 
3667
5308
static void CKA_FindNuc(SeqEntryPtr sep, Pointer data, Int4 index, Int2 indent)
3700
5341
   return 0;
3701
5342
}
3702
5343
 
 
5344
static void amconssetfree(AMConsSetPtr acp)
 
5345
{
 
5346
   AMConsSetPtr  acp_next;
 
5347
 
 
5348
   while (acp != NULL)
 
5349
   {
 
5350
      acp_next = acp->next;
 
5351
      MemFree(acp->starts);
 
5352
      MemFree(acp->stops);
 
5353
      MemFree(acp->strands);
 
5354
      MemFree(acp);
 
5355
      acp = acp_next;
 
5356
   }
 
5357
}
 
5358
 
 
5359
static int LIBCALLBACK CKA_SortForConsistent(VoidPtr ptr1, VoidPtr ptr2)
 
5360
{
 
5361
   AMConsSetPtr  acp1;
 
5362
   AMConsSetPtr  acp2;
 
5363
   FloatHi       bitscore;
 
5364
   FloatHi       evalue;
 
5365
   Int4          number;
 
5366
   SAIndex2Ptr   saip1;
 
5367
   SAIndex2Ptr   saip2;
 
5368
 
 
5369
   acp1 = *((AMConsSetPtr PNTR)ptr1);
 
5370
   acp2 = *((AMConsSetPtr PNTR)ptr2);
 
5371
   saip1 = (SAIndex2Ptr)(acp1->sap->saip);
 
5372
   saip2 = (SAIndex2Ptr)(acp2->sap->saip);
 
5373
   if (saip1->score == 0)
 
5374
      GetScoreAndEvalue(acp1->sap, &saip1->score, &bitscore, &evalue, &number);
 
5375
   if (saip2->score == 0)
 
5376
      GetScoreAndEvalue(acp2->sap, &saip2->score, &bitscore, &evalue, &number);
 
5377
   if (saip1->score > saip2->score)
 
5378
      return -1;
 
5379
   else if (saip1->score < saip2->score)
 
5380
      return 1;
 
5381
   else
 
5382
      return 0;
 
5383
}
 
5384
 
 
5385
static void CKA_RemoveInconsistentAlnsFromSet(SeqAlignPtr sap_head, Int4 fuzz)
 
5386
{
 
5387
   AMConsSetPtr  acp;
 
5388
   AMConsSetPtr  acp_head;
 
5389
   AMConsSetPtr  acp_prev;
 
5390
   AMConsSetPtr  PNTR acparray;
 
5391
   DenseSegPtr   dsp;
 
5392
   Int4          i;
 
5393
   Int4          j;
 
5394
   Int4          k;
 
5395
   Int4          lfuzz;
 
5396
   SeqAlignPtr   newsap;
 
5397
   Int4          numrows;
 
5398
   Int4          numsaps;
 
5399
   Int4          orientation;
 
5400
   Int4          row;
 
5401
   SAIndex2Ptr   saip;
 
5402
   SeqAlignPtr   salp_head;
 
5403
   SeqAlignPtr   salp_prev;
 
5404
   SeqAlignPtr   sap;
 
5405
   SeqAlignPtr   sapnext;
 
5406
   Int4          score;
 
5407
   SeqIdPtr      sip;
 
5408
   SeqIdPtr      sip_head;
 
5409
   Uint1         strand;
 
5410
 
 
5411
   lfuzz = fuzz;
 
5412
   if (fuzz < 0)
 
5413
      fuzz = 1;
 
5414
   sap = (SeqAlignPtr)(sap_head->segs);
 
5415
   if (sap->next == NULL)
 
5416
      return;
 
5417
   dsp = (DenseSegPtr)(sap->segs);
 
5418
   sip_head = dsp->ids;
 
5419
   numrows = AlnMgr2GetNumRows(sap);
 
5420
   acp_head = NULL;
 
5421
   strand = AlnMgr2GetNthStrand(sap, 1);
 
5422
   numsaps = 0;
 
5423
   while (sap != NULL)
 
5424
   {
 
5425
      if (AlnMgr2GetNumRows(sap) != numrows)
 
5426
      {
 
5427
         amconssetfree(acp_head);
 
5428
         return;
 
5429
      }
 
5430
      numsaps++;
 
5431
      acp = (AMConsSetPtr)MemNew(sizeof(AMConsSet));
 
5432
      acp->starts = (Int4Ptr)MemNew(numrows*sizeof(Int4));
 
5433
      acp->stops = (Int4Ptr)MemNew(numrows*sizeof(Int4));
 
5434
      acp->strands = (Uint1Ptr)MemNew(numrows*sizeof(Uint1));
 
5435
      acp->which = (Int4Ptr)MemNew(numrows*sizeof(Int4));
 
5436
      acp->sap = sap;
 
5437
      if (acp_head != NULL)
 
5438
      {
 
5439
         acp_prev->next = acp;
 
5440
         acp_prev = acp;
 
5441
      } else
 
5442
         acp_head = acp_prev = acp;
 
5443
      sip = sip_head;
 
5444
      row = AlnMgr2GetFirstNForSip(sap, sip);
 
5445
      if (row <= 0)
 
5446
      {
 
5447
         amconssetfree(acp_head);
 
5448
         return;
 
5449
      }
 
5450
      if (acp->strands[row] != strand)
 
5451
      {
 
5452
         sapnext = acp->sap->next;
 
5453
         acp->sap->next = NULL;
 
5454
         score = ((SAIndex2Ptr)(acp->sap->saip))->score;
 
5455
         SeqAlignListReverseStrand(acp->sap);
 
5456
         AMAlignIndexFreeEitherIndex(acp->sap);
 
5457
         AlnMgr2IndexSingleChildSeqAlign(acp->sap);
 
5458
         saip = (SAIndex2Ptr)(acp->sap->saip);
 
5459
         saip->score = score;
 
5460
         acp->strands[row] = strand;
 
5461
         acp->sap->next = sapnext;
 
5462
      }
 
5463
      for (i=0; i<numrows; i++)
 
5464
      {
 
5465
         acp->which[i] = row;
 
5466
         AlnMgr2GetNthSeqRangeInSA(sap, i+1, &acp->starts[i], &acp->stops[i]);
 
5467
         acp->strands[i] = AlnMgr2GetNthStrand(sap, i+1);
 
5468
      }
 
5469
      sap = sap->next;
 
5470
   }
 
5471
   acparray = (AMConsSetPtr PNTR)MemNew(numsaps*sizeof(AMConsSetPtr));
 
5472
   acp = acp_head;
 
5473
   i = 0;
 
5474
   while (acp != NULL)
 
5475
   {
 
5476
      acparray[i] = acp;
 
5477
      acp = acp->next;
 
5478
      i++;
 
5479
   }
 
5480
   HeapSort(acparray, numsaps, sizeof(AMConsSetPtr), CKA_SortForConsistent);
 
5481
   /* orientation -1 means that ith is before jth in ALL rows, 1 means ith is after jth in ALL rows */
 
5482
   for (i=0; i<numsaps; i++)
 
5483
   {
 
5484
      if (acparray[i]->used != -1)
 
5485
      {
 
5486
         for (j=i+1; j<numsaps; j++)
 
5487
         {
 
5488
            orientation = 0;
 
5489
            for (k=0; acparray[j]->used != -1 && k<numrows; k++)
 
5490
            {
 
5491
               if (acparray[i]->starts[k] - fuzz < acparray[j]->starts[k])
 
5492
               {
 
5493
                  if (acparray[i]->stops[k] - fuzz < acparray[j]->starts[k])
 
5494
                  {
 
5495
                     if (orientation == 0)
 
5496
                     {
 
5497
                        if (acparray[i]->strands[k] == Seq_strand_minus)
 
5498
                           orientation = 1;
 
5499
                        else
 
5500
                           orientation = -1;
 
5501
                     }
 
5502
                  } else
 
5503
                  {
 
5504
                     if (lfuzz >= 0) /* just mark it for deletion */
 
5505
                        acparray[j]->used = -1;
 
5506
                     else /* truncate it */
 
5507
                     {
 
5508
                        if (acparray[j]->stops[k] >
 
5509
                            acparray[i]->stops[k] + CKA_blast_wordsize)
 
5510
                        {
 
5511
                           newsap = AlnMgr2GetSubAlign(acparray[j]->sap, acparray[i]->stops[k]+1,
 
5512
 acparray[j]->stops[k], k+1, TRUE);
 
5513
                           AlnMgr2IndexSingleChildSeqAlign(newsap);
 
5514
                           SeqAlignFree(acparray[j]->sap);
 
5515
                           acparray[j]->sap = newsap;
 
5516
                           acparray[j]->starts[k] = acparray[i]->stops[k]+1;
 
5517
                        } else
 
5518
                           acparray[j]->used = -1;
 
5519
                     }
 
5520
                  }
 
5521
               } else if (acparray[i]->starts[k] - fuzz > acparray[j]->starts[k])
 
5522
               {
 
5523
                 if (acparray[i]->starts[k] + fuzz > acparray[j]->stops[k])
 
5524
                  {
 
5525
                     if (orientation == 0)
 
5526
                     {
 
5527
                        if (acparray[i]->strands[k] == Seq_strand_minus)
 
5528
                           orientation = -1;
 
5529
                        else
 
5530
                           orientation = 1;
 
5531
                     }
 
5532
                  } else
 
5533
                  {
 
5534
                     if (lfuzz >= 0) /* mark for deletion */
 
5535
                        acparray[j]->used = -1;
 
5536
                     else /* truncate */
 
5537
                     {
 
5538
                        if (acparray[j]->starts[k] <
 
5539
                            acparray[i]->starts[k] - CKA_blast_wordsize)
 
5540
                        {
 
5541
                           newsap = AlnMgr2GetSubAlign(acparray[j]->sap, acparray[j]->starts[k], acparray[i]->starts[k]-1, k+1, TRUE);
 
5542
                           AlnMgr2IndexSingleChildSeqAlign(newsap);
 
5543
                           SeqAlignFree(acparray[j]->sap);
 
5544
                           acparray[j]->sap = newsap;
 
5545
                           acparray[j]->stops[k] = acparray[i]->starts[k]-1;
 
5546
                        } else
 
5547
                           acparray[j]->used = -1;
 
5548
                     }
 
5549
                  }
 
5550
               } else
 
5551
                  acparray[j]->used = -1;
 
5552
            }
 
5553
         }
 
5554
      }
 
5555
   }
 
5556
   /* now free all the unused ones, stick the rest back together, reindex, and return */
 
5557
   salp_head = salp_prev = NULL;
 
5558
   for (i=0; i<numsaps; i++)
 
5559
   {
 
5560
      if (acparray[i]->used == -1)
 
5561
      {
 
5562
         SeqAlignFree(acparray[i]->sap);
 
5563
         acparray[i]->sap = NULL;
 
5564
      } else
 
5565
      {
 
5566
         if (salp_head != NULL)
 
5567
         {
 
5568
            salp_prev->next = acparray[i]->sap;
 
5569
            salp_prev = acparray[i]->sap;
 
5570
            salp_prev->next = NULL;
 
5571
         } else
 
5572
         {
 
5573
            salp_head = salp_prev = acparray[i]->sap;
 
5574
            salp_prev->next = NULL;
 
5575
         }
 
5576
      }
 
5577
   }
 
5578
   amconssetfree(acp_head);
 
5579
   MemFree(acparray);
 
5580
   sap_head->segs = (Pointer)(salp_head);
 
5581
   AMAlignIndex2Free2(sap_head->saip);
 
5582
   AlnMgr2IndexLite(sap_head);
 
5583
}
 
5584
 
 
5585
static BioseqPtr ReadFromTraceDb (CharPtr number)
 
5586
 
 
5587
{
 
5588
  BioseqPtr    bsp = NULL;
 
5589
  CONN         conn;
 
5590
  time_t       currtime, starttime;
 
5591
  FILE         *fp;
 
5592
  Int2         max = 0;
 
5593
  size_t       n_written;
 
5594
  Char         path [PATH_MAX];
 
5595
  Char         query [64];
 
5596
  SeqEntryPtr  sep = NULL;
 
5597
  EIO_Status   status;
 
5598
  STimeout     timeout;
 
5599
  long int     val;
 
5600
 
 
5601
  if (StringHasNoText (number)) return NULL;
 
5602
  if (sscanf (number, "%ld", &val) != 1) return NULL;
 
5603
  sprintf (query, "cmd=raw&query=retrieve+fasta+%ld", (long) val);
 
5604
  conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80, "/Traces/trace.cgi",
 
5605
                             query, "Sequin", 30, eMIME_T_NcbiData,
 
5606
                             eMIME_Fasta, eENCOD_None, 0);
 
5607
  if (conn == NULL) return NULL;
 
5608
  status = CONN_Write (conn, (const void *) query, StringLen (query),
 
5609
                       &n_written, eIO_WritePersist);
 
5610
  if (status != eIO_Success) return NULL;
 
5611
  QUERY_SendQuery (conn);
 
5612
 
 
5613
#ifdef OS_MAC 
 
5614
  timeout.sec = 0;
 
5615
  timeout.usec = 0;
 
5616
#else
 
5617
  timeout.sec = 100;
 
5618
  timeout.usec = 0;
 
5619
#endif
 
5620
 
 
5621
  starttime = GetSecs ();
 
5622
  while ((status = CONN_Wait (conn, eIO_Read, &timeout)) != eIO_Success && max < 300) {
 
5623
    currtime = GetSecs ();
 
5624
    max = currtime - starttime;
 
5625
  }
 
5626
 
 
5627
  if (status == eIO_Success) {
 
5628
    TmpNam (path);
 
5629
    fp = FileOpen (path, "w");
 
5630
    QUERY_CopyResultsToFile (conn, fp);
 
5631
    FileClose (fp);
 
5632
    /*
 
5633
    LaunchGeneralTextViewer (path, "QueueFastaQueryToURL results");
 
5634
    */
 
5635
    fp = FileOpen (path, "r");
 
5636
    sep = FastaToSeqEntry (fp, TRUE);
 
5637
    FileClose (fp);
 
5638
    FileRemove (path);
 
5639
    if (sep != NULL) {
 
5640
      bsp = FindNucBioseq (sep);
 
5641
    }
 
5642
  }
 
5643
  CONN_Close (conn);
 
5644
 
 
5645
  return bsp;
 
5646
}
 
5647
 
 
5648
 
3703
5649
static SeqAlignPtr CKA_MakeAlign(BioseqPtr bsp, CKA_AccPtr acc_head)
3704
5650
{
3705
5651
   CKA_AccPtr           acc;
 
5652
   CKA_AccPtr           acc_new;
 
5653
   CKA_AccPtr           acc_new_head_head;
 
5654
   CKA_AccPtr           acc_new_head;
 
5655
   CKA_AccPtr           acc_new_prev;
3706
5656
   SeqAlignPtr          allsap;
3707
5657
   SeqAlignPtr          allsap_prev;
3708
5658
   AMAlignIndex2Ptr     amaip;
3709
5659
   BioseqPtr            bsp_tmp;
3710
5660
   Int4                 i;
3711
5661
   BLAST_OptionsBlkPtr  options;
3712
 
   SeqAlignPtr          salp;
3713
5662
   SeqAlignPtr          sap_new;
 
5663
   SeqAlignPtr          sap_tmp;
 
5664
   SeqAlignPtr          sap_tmp_next;
3714
5665
   SeqIdPtr             sip;
3715
5666
   Uint1                strand;
3716
5667
 
3719
5670
   acc = acc_head;
3720
5671
   allsap = NULL;
3721
5672
   allsap_prev = NULL;
 
5673
   acc_new_head_head = acc_new_prev = NULL;
3722
5674
   while (acc != NULL)
3723
5675
   {
3724
5676
      options = BLASTOptionNew("blastn", TRUE);
3725
 
      options->wordsize = 32;
3726
 
      options->gap_open = 0;
3727
 
      options->gap_extend = 0;
3728
 
   /* faster with no filtering */
3729
 
      options->is_megablast_search = TRUE;
3730
 
      sip = SeqIdFromAccessionDotVersion(acc->accession);
3731
 
      bsp_tmp = BioseqLockById(sip);
 
5677
      /*if (bsp->length > 10000)*/
 
5678
      {
 
5679
/*    faster with no filtering */
 
5680
         options->is_megablast_search = TRUE;
 
5681
         options->gap_open = options->gap_extend = 0;
 
5682
         options->wordsize = CKA_blast_wordsize;
 
5683
      }/* else
 
5684
         options->filter_string = StringSave("m L;R");*/
 
5685
      options->expect_value = CKA_blast_expect_value;
 
5686
      bsp_tmp = NULL;
 
5687
      if (StringNICmp (acc->accession, "ti", 2) == 0) {
 
5688
        bsp_tmp = ReadFromTraceDb (acc->accession + 2);
 
5689
      } else {
 
5690
        sip = SeqIdFromAccessionDotVersion(acc->accession);
 
5691
        bsp_tmp = BioseqLockById(sip);
 
5692
      }
 
5693
      if (bsp_tmp == NULL) break;
 
5694
      if (bsp_tmp->id->next) {
 
5695
        /* find the best accession */
 
5696
        SeqIdPtr sip = SeqIdDup(SqnSeqIdFindBestAccession(bsp_tmp->id));
 
5697
        bsp_tmp->id = SeqIdSetFree(bsp_tmp->id);
 
5698
        bsp_tmp->id = sip;
 
5699
      }
3732
5700
      if (!ISA_na(bsp_tmp->mol))
3733
5701
      {
3734
5702
         BioseqUnlock(bsp_tmp);
3735
5703
         Message(MSG_ERROR, "%s is not a nucleotide bioseq.", acc->accession);
3736
5704
         break;
3737
5705
      }
3738
 
      acc->sap = BlastTwoSequences(bsp_tmp, bsp, "blastn", options);
 
5706
      WatchCursor();
 
5707
      if (acc->start_acc >=0 && acc->stop_acc >=0 &&
 
5708
          acc->start_acc < bsp_tmp->length &&
 
5709
          acc->start_acc < bsp_tmp->length) {
 
5710
        SeqLocPtr slp1, slp2;
 
5711
        if (acc->start_acc <= acc->stop_acc) {
 
5712
          slp1 = SeqLocIntNew
 
5713
            (acc->start_acc, acc->stop_acc, Seq_strand_plus, bsp_tmp->id);
 
5714
        } else {
 
5715
          slp1 = SeqLocIntNew
 
5716
            (acc->stop_acc, acc->start_acc, Seq_strand_minus, bsp_tmp->id);
 
5717
        }
 
5718
        slp2 = SeqLocIntNew(0, bsp->length-1, Seq_strand_plus, bsp->id);
 
5719
        acc->sap = BlastTwoSequencesByLoc(slp1, slp2, "blastn", options);
 
5720
        SeqLocFree(slp1);
 
5721
        SeqLocFree(slp2);
 
5722
      } else {
 
5723
        acc->sap = BlastTwoSequences(bsp_tmp, bsp, "blastn", options);
 
5724
      }
 
5725
      BLASTOptionDelete(options);
 
5726
      ArrowCursor();
 
5727
      acc->start_acc = acc->stop_acc = 0; /* reset, for later usage */
3739
5728
      if (acc->sap != NULL)
3740
5729
         SPI_flip_sa_list(acc->sap);
 
5730
      acc_new_head = NULL;
3741
5731
      if (acc->sap != NULL && acc->sap->next != NULL)
3742
5732
      {
3743
5733
         AlnMgr2IndexLite(acc->sap);
3744
 
         amaip = (AMAlignIndex2Ptr)(acc->sap->saip);
3745
 
         HeapSort(amaip->saps, amaip->numsaps, sizeof(SeqAlignPtr), CKA_CompareAlns);
3746
 
         salp = (amaip->saps[0]);
3747
 
         sap_new = SeqAlignDup(salp);
3748
 
         SeqAlignSetFree(acc->sap);
3749
 
         acc->sap = sap_new;
3750
 
      }
3751
 
      if (acc->sap != NULL)
3752
 
      {
 
5734
         if (!CKA_blast_allow_repeats) {
 
5735
           CKA_RemoveInconsistentAlnsFromSet(acc->sap, -1);
 
5736
         }
 
5737
         sap_tmp = acc->sap;
 
5738
         acc->sap = (SeqAlignPtr)(acc->sap->segs);
 
5739
         sap_tmp->segs = NULL;
 
5740
         SeqAlignFree(sap_tmp);
 
5741
         sap_tmp = acc->sap->next;
 
5742
         acc->sap->next = NULL;
 
5743
         while (sap_tmp != NULL)
 
5744
         {
 
5745
            AlnMgr2IndexSingleChildSeqAlign(sap_tmp);
 
5746
            sap_tmp_next = sap_tmp->next;
 
5747
            sap_tmp->next = NULL;
 
5748
            acc_new = (CKA_AccPtr)MemNew(sizeof(CKA_Acc));
 
5749
            acc_new->accession = StringSave(acc->accession);
 
5750
            acc_new->sip_whole = SeqIdDup(acc->sip_whole);
 
5751
            acc_new->sap = sap_tmp;
 
5752
            sap_tmp = sap_tmp_next;
 
5753
            if (!acc_new_head) {
 
5754
              acc_new_head = acc_new;
 
5755
            }
 
5756
            if (acc_new_prev) {
 
5757
              acc_new_prev->next = acc_new;
 
5758
            }
 
5759
            acc_new_prev = acc_new;
 
5760
         }
 
5761
      } else if (acc->sap != NULL)
3753
5762
         AlnMgr2IndexSingleChildSeqAlign(acc->sap);
 
5763
      if (acc->sap != NULL)
 
5764
      {
3754
5765
         strand = AlnMgr2GetNthStrand(acc->sap, 1);
3755
5766
         if (strand == Seq_strand_minus)
3756
5767
         {
3758
5769
            SAIndex2Free2(acc->sap->saip);
3759
5770
            acc->sap->saip = NULL;
3760
5771
         }
3761
 
         if (allsap != NULL && acc->sap != NULL)
3762
 
         {
3763
 
            allsap_prev->next = acc->sap;
 
5772
      }
 
5773
      if (allsap != NULL && acc->sap != NULL)
 
5774
      {
 
5775
         allsap_prev->next = acc->sap;
 
5776
         allsap_prev = allsap_prev->next;;
 
5777
      } else if (acc->sap != NULL)
 
5778
         allsap_prev = allsap = (acc->sap);
 
5779
      acc_new = acc_new_head;
 
5780
      while (acc_new != NULL)
 
5781
      {
 
5782
         strand = AlnMgr2GetNthStrand(acc_new->sap, 1);
 
5783
         if (strand == Seq_strand_minus)
 
5784
         {
 
5785
            SeqAlignListReverseStrand(acc_new->sap);
 
5786
            SAIndex2Free2(acc_new->sap->saip);
 
5787
            acc_new->sap->saip = NULL;
 
5788
         }
 
5789
         if (allsap != NULL)
 
5790
         {
 
5791
            allsap_prev->next = acc_new->sap;
3764
5792
            allsap_prev = allsap_prev->next;;
3765
 
         } else if (acc->sap != NULL)
3766
 
            allsap_prev = allsap = (acc->sap);
 
5793
         } else
 
5794
            allsap_prev = allsap = acc_new->sap;
 
5795
         acc_new = acc_new->next;
3767
5796
      }
 
5797
      if (allsap_prev != NULL)
 
5798
      {
 
5799
         while (allsap_prev->next != NULL)
 
5800
         {
 
5801
            allsap_prev = allsap_prev->next;
 
5802
         }
 
5803
      }  
3768
5804
      BioseqUnlock(bsp_tmp);
3769
5805
      acc = acc->next;
3770
 
      BLASTOptionDelete(options);
3771
 
   }
 
5806
      if (!acc_new_head_head) {
 
5807
        acc_new_head_head = acc_new_head;
 
5808
      }
 
5809
   }
 
5810
   acc = acc_head;
 
5811
   while (acc->next != NULL)
 
5812
   {
 
5813
      acc = acc->next;
 
5814
   }
 
5815
   acc->next = acc_new_head_head;
3772
5816
   if (allsap == NULL)
3773
5817
      return NULL;
3774
5818
   sap_new = SeqAlignNew();
3787
5831
   return allsap;
3788
5832
}
3789
5833
 
 
5834
static void DoCreateSeqHistTPA (IteM i)
 
5835
{
 
5836
  BaseFormPtr        bfp;
 
5837
  SeqEntryPtr        sep;
 
5838
 
 
5839
#ifdef WIN_MAC
 
5840
  bfp = currentFormDataPtr;
 
5841
#else
 
5842
  bfp = GetObjectExtra (i);
 
5843
#endif
 
5844
  if (bfp == NULL) return;
 
5845
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
5846
  if (sep == NULL) return;
 
5847
 
 
5848
  CKA_RunChecker(sep);
 
5849
 
 
5850
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
5851
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
5852
}
 
5853
 
3790
5854
extern void CreateSeqHistTPA (IteM i);
3791
 
 
3792
5855
extern void CreateSeqHistTPA (IteM i)
3793
5856
{
3794
 
  BaseFormPtr        bfp;
3795
 
  SeqEntryPtr        sep;
 
5857
  CKA_blast_wordsize = 28;
 
5858
  CKA_blast_expect_value = 0.000001;
 
5859
  CKA_blast_allow_repeats = FALSE;
 
5860
  DoCreateSeqHistTPA(i);
 
5861
}
 
5862
 
 
5863
static SeqAlignPtr DeltaSeq2SeqAlign(BioseqPtr bsp)
 
5864
{
 
5865
  DeltaSeqPtr  deltasp;
 
5866
  SeqLocPtr    slp;
 
5867
  SeqAlignPtr  sap, sap_head = NULL;
 
5868
  DenseSegPtr  dsp;
 
5869
  SeqIntPtr    intp;
 
5870
  SeqLitPtr    litp;
 
5871
  int          curr_start = 0;
 
5872
 
 
5873
  if (bsp == NULL || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4) {
 
5874
    return NULL;
 
5875
  }
 
5876
  if (!(deltasp = (DeltaSeqPtr) bsp->seq_ext)) {
 
5877
    return NULL;
 
5878
  }
 
5879
 
 
5880
  while (deltasp) {
 
5881
    if (deltasp->choice == 1) { 
 
5882
      slp = (SeqLocPtr) deltasp->data.ptrvalue;
 
5883
      if (sap_head) {
 
5884
        sap = sap->next = SeqAlignNew();
 
5885
      } else {
 
5886
        sap_head = sap = SeqAlignNew();
 
5887
      }
 
5888
      dsp = DenseSegNew();
 
5889
      
 
5890
      sap->type = SAT_PARTIAL;
 
5891
      sap->segtype = SAS_DENSEG;
 
5892
      sap->dim = 2;
 
5893
      sap->segs = (Pointer)(dsp);
 
5894
      dsp->dim = 2;
 
5895
      dsp->numseg = 1;
 
5896
      dsp->lens = (Int4Ptr)MemNew((dsp->numseg)*sizeof(Int4));
 
5897
      dsp->starts = (Int4Ptr)MemNew((dsp->numseg)*(dsp->dim)*sizeof(Int4));
 
5898
      dsp->strands = (Uint1Ptr)MemNew((dsp->numseg)*(dsp->dim)*sizeof(Int4));
 
5899
      
 
5900
      dsp->ids = SeqIdDup(bsp->id);
 
5901
      if (dsp->ids->next) {
 
5902
        /* Dense-seg ids do not support lists, only 1 id per sequence */
 
5903
        SeqIdFree(dsp->ids->next);
 
5904
        dsp->ids->next = NULL;
 
5905
      }
 
5906
      switch (slp->choice) {
 
5907
      case SEQLOC_INT:
 
5908
        intp = (SeqIntPtr) slp->data.ptrvalue;
 
5909
        dsp->starts[0] = curr_start;
 
5910
        dsp->starts[1] = intp->from;
 
5911
        curr_start += dsp->lens[0] = intp->to - intp->from + 1;
 
5912
        dsp->strands[0] = Seq_strand_plus;
 
5913
        dsp->strands[1] = intp->strand;
 
5914
        dsp->ids->next = SeqIdDup(intp->id);
 
5915
        break;
 
5916
      default:
 
5917
        /* exception */
 
5918
        break;
 
5919
      }
 
5920
    } else if (deltasp->choice == 2) { 
 
5921
      litp = (SeqLitPtr) deltasp->data.ptrvalue;
 
5922
      if (litp != NULL) {
 
5923
        curr_start += litp->length;
 
5924
      }
 
5925
    }
 
5926
    deltasp = deltasp->next;
 
5927
  }
 
5928
  return sap_head;
 
5929
}
 
5930
 
 
5931
static void DoDeltaHist (BioseqPtr bsp, Pointer userdata)
 
5932
 
 
5933
{
 
5934
  SeqAlignPtr  salp;
 
5935
  SeqHistPtr   shp;
 
5936
 
 
5937
  if (bsp == NULL || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4) return;
 
5938
  shp = bsp->hist;
 
5939
  if (shp != NULL && shp->assembly != NULL) return;
 
5940
  salp = DeltaSeq2SeqAlign (bsp);
 
5941
  if (salp == NULL) return;
 
5942
  if (shp == NULL) {
 
5943
    shp = SeqHistNew ();
 
5944
    bsp->hist = shp;
 
5945
  }
 
5946
  if (shp == NULL) return;
 
5947
  shp->assembly = salp;
 
5948
}
 
5949
 
 
5950
extern void CreateSeqHistDelta (IteM i);
 
5951
extern void CreateSeqHistDelta (IteM i)
 
5952
{
 
5953
  BaseFormPtr  bfp;
 
5954
  SeqEntryPtr  sep;
3796
5955
 
3797
5956
#ifdef WIN_MAC
3798
5957
  bfp = currentFormDataPtr;
3803
5962
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3804
5963
  if (sep == NULL) return;
3805
5964
 
3806
 
  CKA_RunChecker(sep);
 
5965
  VisitBioseqsInSep (sep, NULL, DoDeltaHist);
3807
5966
 
3808
5967
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3809
5968
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
3810
5969
}
3811
5970
 
 
5971
static TexT blast_wordsize_text = NULL;
 
5972
static TexT blast_expect_value_text = NULL;
 
5973
static ButtoN blast_allow_repeats_button = NULL;
 
5974
static IteM blast_i;
 
5975
 
 
5976
static void DoAcceptBlastOptions (ButtoN b)
 
5977
 
 
5978
{
 
5979
   Char    buf [64];
 
5980
   long    val1;
 
5981
   FloatHi val2;
 
5982
 
 
5983
   GetTitle (blast_wordsize_text, buf, sizeof (buf));
 
5984
   if (sscanf (buf, "%ld", &val1) == 1) {
 
5985
     CKA_blast_wordsize = CKA_blast_detailed_wordsize = (Int4) val1;
 
5986
   }
 
5987
   GetTitle (blast_expect_value_text, buf, sizeof (buf));
 
5988
   if (sscanf (buf, "%lf", &val2) == 1) {
 
5989
     CKA_blast_expect_value = CKA_blast_detailed_expect_value = (FloatHi) val2;
 
5990
   }
 
5991
   CKA_blast_allow_repeats = CKA_blast_detailed_allow_repeats =
 
5992
     (Boolean) GetStatus (blast_allow_repeats_button);
 
5993
   Remove (ParentWindow (b));
 
5994
   DoCreateSeqHistTPA(blast_i);
 
5995
}
 
5996
 
 
5997
extern void CreateSeqHistTPADetailed (IteM i);
 
5998
extern void CreateSeqHistTPADetailed (IteM i)
 
5999
{
 
6000
   GrouP   c;
 
6001
   GrouP   g;
 
6002
   GrouP   h;
 
6003
   WindoW  w;
 
6004
   Char    buf[64];
 
6005
 
 
6006
   blast_i = i;
 
6007
 
 
6008
   w = FixedWindow (-50, -33, -10, -10, "Blast Options", NULL);
 
6009
   h = HiddenGroup (w, -1, 0, NULL);
 
6010
   SetGroupSpacing (h, 3, 2);
 
6011
   g = HiddenGroup (h, 2, 0, NULL);
 
6012
 
 
6013
   StaticPrompt (g, "Word Size", 0, dialogTextHeight, programFont, 'l');
 
6014
   if (CKA_blast_detailed_wordsize <= 0) {
 
6015
     CKA_blast_detailed_wordsize = 14;
 
6016
   }
 
6017
   CKA_blast_wordsize = CKA_blast_detailed_wordsize;
 
6018
   sprintf(buf, "%d", CKA_blast_wordsize);
 
6019
   blast_wordsize_text = DialogText (g, buf, 10, NULL);
 
6020
 
 
6021
   StaticPrompt (g, "Expect Value", 0, dialogTextHeight, programFont, 'l');
 
6022
   if (CKA_blast_detailed_expect_value <= 0.0) {
 
6023
     CKA_blast_detailed_expect_value = 0.001;
 
6024
   }
 
6025
   CKA_blast_expect_value = CKA_blast_detailed_expect_value;
 
6026
   sprintf(buf, "%f", CKA_blast_expect_value);
 
6027
   blast_expect_value_text = DialogText (g, buf, 10, NULL);
 
6028
 
 
6029
   blast_allow_repeats_button = CheckBox (g, "Allow Repeats", NULL);
 
6030
   if (CKA_blast_detailed_allow_repeats) {
 
6031
     SetStatus(blast_allow_repeats_button, TRUE);
 
6032
   }
 
6033
 
 
6034
   c = HiddenGroup (w, 2, 0, NULL);
 
6035
   SetGroupSpacing (c, 5, 5);
 
6036
   DefaultButton (c, "Accept", DoAcceptBlastOptions);
 
6037
   PushButton (c, "Cancel", StdCancelButtonProc);
 
6038
   AlignObjects (ALIGN_CENTER, (HANDLE) h, (HANDLE) c, NULL);
 
6039
   RealizeWindow (w);
 
6040
   Show (w);
 
6041
   Select (w);
 
6042
   Select (blast_wordsize_text);
 
6043
}
 
6044
 
3812
6045
extern Int2 LIBCALLBACK AssemblyUserGenFunc (Pointer data);
3813
6046
 
3814
6047
typedef struct assemblyuserdialog {
3825
6058
 
3826
6059
{
3827
6060
  AssemblyUserDialogPtr  adp;
 
6061
  Char                   buf [16];
3828
6062
  UserFieldPtr           curr;
 
6063
  Int4                   from;
3829
6064
  ValNodePtr             head = NULL;
3830
6065
  ObjectIdPtr            oip;
3831
6066
  CharPtr                str;
 
6067
  CharPtr                tmp;
 
6068
  Int4                   to;
3832
6069
  UserFieldPtr           ufp;
3833
6070
  UserObjectPtr          uop;
3834
6071
 
3843
6080
 
3844
6081
  for (curr = uop->data; curr != NULL; curr = curr->next) {
3845
6082
    if (curr->choice != 11) continue;
 
6083
    str = NULL;
 
6084
    from = 0;
 
6085
    to = 0;
3846
6086
    for (ufp = curr->data.ptrvalue; ufp != NULL; ufp = ufp->next) {
3847
 
      if (ufp->choice != 1) continue;
3848
6087
      oip = ufp->label;
3849
 
      if (oip == NULL || StringICmp (oip->str, "accession") != 0) continue;
3850
 
      str = (CharPtr) ufp->data.ptrvalue;
3851
 
      if (StringHasNoText (str)) continue;
3852
 
      ValNodeCopyStr (&head, 0, (Pointer) str);
3853
 
    }
 
6088
      if (oip == NULL) continue;
 
6089
      if (StringICmp (oip->str, "accession") == 0 && ufp->choice == 1) {
 
6090
        str = (CharPtr) ufp->data.ptrvalue;
 
6091
      } else if (StringICmp (oip->str, "from") == 0 && ufp->choice == 2) {
 
6092
        from = (Int4) ufp->data.intvalue;
 
6093
      } else if (StringICmp (oip->str, "to") == 0 && ufp->choice == 2) {
 
6094
        to = (Int4) ufp->data.intvalue;
 
6095
      }
 
6096
    }
 
6097
    if (StringHasNoText (str)) continue;
 
6098
    tmp = MemNew (StringLen (str) + 32);
 
6099
    StringCpy (tmp, str);
 
6100
    StringCat (tmp, "\t");
 
6101
    if (from > 0 || to > 0) {
 
6102
      sprintf (buf, "%ld", (long) (from + 1));
 
6103
      StringCat (tmp, buf);
 
6104
      StringCat (tmp, "\t");
 
6105
      sprintf (buf, "%ld", (long) (to + 1));
 
6106
      StringCat (tmp, buf);
 
6107
      StringCat (tmp, "\t");
 
6108
    } else {
 
6109
      StringCat (tmp, "\t\t");
 
6110
    }
 
6111
    ValNodeAddStr (&head, 0, (Pointer) tmp);
3854
6112
  }
3855
6113
 
3856
6114
  PointerToDialog (adp->accns, (Pointer) head);
3857
6115
  ValNodeFreeData (head);
3858
6116
}
3859
6117
 
 
6118
static void DoAddAccessionToTpa (UserObjectPtr uop, CharPtr last)
 
6119
 
 
6120
{
 
6121
  Int4      from = 0;
 
6122
  CharPtr   ptr1, ptr2, ptr3;
 
6123
  Int4      to = 0;
 
6124
  long int  val;
 
6125
 
 
6126
  ptr1 = StringChr (last, '\t');
 
6127
  if (ptr1 != NULL) {
 
6128
    *ptr1 = '\0';
 
6129
    ptr1++;
 
6130
    ptr2 = StringChr (ptr1, '\t');
 
6131
    if (ptr2 != NULL) {
 
6132
      *ptr2 = '\0';
 
6133
      ptr2++;
 
6134
      ptr3 = StringChr (ptr2, '\t');
 
6135
      if (ptr3 != NULL) {
 
6136
        *ptr3 = '\0';
 
6137
      }
 
6138
    }
 
6139
    if (sscanf (ptr1, "%ld", &val) == 1 && val > 0) {
 
6140
      from = val - 1;
 
6141
      if (sscanf (ptr2, "%ld", &val) == 1 && val > 0) {
 
6142
        to = val - 1;
 
6143
      } else {
 
6144
        from = 0;
 
6145
        to = 0;
 
6146
      }
 
6147
    }
 
6148
  }
 
6149
  AddAccessionToTpaAssemblyUserObject (uop, last, from, to);
 
6150
}
 
6151
 
3860
6152
static Pointer AssemblyDialogToUserObjectPtr (DialoG d)
3861
6153
 
3862
6154
{
3887
6179
    ptr = last;
3888
6180
    ch = *ptr;
3889
6181
    while (ch != '\0') {
3890
 
      if (ch == ',') {
 
6182
      if (ch == ',' || ch == ' ') {
3891
6183
        *ptr = '\0';
3892
6184
        TrimSpacesAroundString (last);
3893
 
        AddAccessionToTpaAssemblyUserObject (uop, last);
 
6185
        DoAddAccessionToTpa (uop, last);
3894
6186
        ptr++;
3895
6187
        last = ptr;
3896
6188
        ch = *ptr;
3901
6193
    }
3902
6194
    if (! StringHasNoText (last)) {
3903
6195
      TrimSpacesAroundString (last);
3904
 
      AddAccessionToTpaAssemblyUserObject (uop, last);
 
6196
      DoAddAccessionToTpa (uop, last);
3905
6197
    }
3906
 
    /* AddAccessionToTpaAssemblyUserObject (uop, str); */
3907
6198
    MemFree (tmp);
3908
6199
  }
3909
6200
 
3912
6203
  return uop;
3913
6204
}
3914
6205
 
 
6206
static void ValNodePtrToAssemblyDialog (DialoG d, Pointer data)
 
6207
 
 
6208
{
 
6209
  ValNodePtr   head;
 
6210
  Int2         j;
 
6211
  ValNodePtr   list;
 
6212
  CharPtr      str;
 
6213
  TagListPtr   tlp;
 
6214
  ValNodePtr   vnp;
 
6215
 
 
6216
  tlp = (TagListPtr) GetObjectExtra (d);
 
6217
  list = (ValNodePtr) data;
 
6218
  if (tlp != NULL) {
 
6219
    head = NULL;
 
6220
    while (list != NULL) {
 
6221
      vnp = ValNodeNew (head);
 
6222
      if (head == NULL) {
 
6223
        head = vnp;
 
6224
      }
 
6225
      if (vnp != NULL) {
 
6226
        str = MemNew (StringLen ((CharPtr) list->data.ptrvalue) + 3);
 
6227
        if (str != NULL) {
 
6228
          StringCpy (str, (CharPtr) list->data.ptrvalue);
 
6229
          StringCat (str, "\n");
 
6230
        }
 
6231
        vnp->data.ptrvalue = str;
 
6232
      }
 
6233
      list = list->next;
 
6234
    }
 
6235
    SendMessageToDialog (tlp->dialog, VIB_MSG_RESET);
 
6236
    tlp->vnp = head;
 
6237
    SendMessageToDialog (tlp->dialog, VIB_MSG_REDRAW);
 
6238
    for (j = 0, vnp = tlp->vnp; vnp != NULL; j++, vnp = vnp->next) {
 
6239
    }
 
6240
    tlp->max = MAX ((Int2) 0, (Int2) (j - tlp->rows + 1));
 
6241
    CorrectBarMax (tlp->bar, tlp->max);
 
6242
    CorrectBarPage (tlp->bar, tlp->rows - 1, tlp->rows - 1);
 
6243
  }
 
6244
}
 
6245
 
 
6246
static Pointer AssemblyDialogToValNodePtr (DialoG d)
 
6247
 
 
6248
{
 
6249
  Char         ch;
 
6250
  ValNodePtr   head;
 
6251
  Int2         j;
 
6252
  Int2         len;
 
6253
  ValNodePtr   list;
 
6254
  Boolean      okay;
 
6255
  CharPtr      str;
 
6256
  TagListPtr   tlp;
 
6257
  ValNodePtr   vnp;
 
6258
 
 
6259
  head = NULL;
 
6260
  tlp = (TagListPtr) GetObjectExtra (d);
 
6261
  if (tlp != NULL && tlp->vnp != NULL) {
 
6262
    list = NULL;
 
6263
    for (vnp = tlp->vnp; vnp != NULL; vnp = vnp->next) {
 
6264
      str = (CharPtr) vnp->data.ptrvalue;
 
6265
      okay = FALSE;
 
6266
      len = StringLen (str);
 
6267
      for (j = 0; j < len; j++) {
 
6268
        ch = str [j];
 
6269
        if (ch != ' ' && ch != '\t' && ch != '\n') {
 
6270
          okay = TRUE;
 
6271
        }
 
6272
      }
 
6273
      if (okay) {
 
6274
        list = ValNodeNew (list);
 
6275
        if (head == NULL) {
 
6276
          head = list;
 
6277
        }
 
6278
        if (list != NULL) {
 
6279
          list->choice = 0;
 
6280
          list->data.ptrvalue = StringSave ((CharPtr) vnp->data.ptrvalue);
 
6281
        }
 
6282
      }
 
6283
    }
 
6284
  }
 
6285
  return (Pointer) head;
 
6286
}
 
6287
 
 
6288
Uint2 assmbly_types [] = {
 
6289
  TAGLIST_TEXT, TAGLIST_TEXT, TAGLIST_TEXT
 
6290
};
 
6291
 
 
6292
Uint2 assmbly_widths [] = {
 
6293
  16, 8, 8, 0
 
6294
};
 
6295
 
3915
6296
static DialoG CreateAssemblyDialog (GrouP g)
3916
6297
 
3917
6298
{
3918
6299
  AssemblyUserDialogPtr  adp;
3919
6300
  GrouP                  p;
3920
6301
  GrouP                  x;
 
6302
  GrouP                  y;
3921
6303
 
3922
6304
  p = HiddenGroup (g, -1, 0, NULL);
3923
6305
  SetGroupSpacing (p, 10, 10);
3931
6313
  adp->fromdialog = AssemblyDialogToUserObjectPtr;
3932
6314
 
3933
6315
  x = HiddenGroup (p, 0, 2, NULL);
3934
 
  StaticPrompt (x, "Accessions", 0, 0, programFont, 'c');
3935
 
  adp->accns = CreateVisibleStringDialog (x, 3, -1, 15);
 
6316
  y = HiddenGroup (x, 3, 0, NULL);
 
6317
  StaticPrompt (y, "Accessions", 16 * stdCharWidth, 0, programFont, 'c');
 
6318
  StaticPrompt (y, "From", 8 * stdCharWidth, 0, programFont, 'c');
 
6319
  StaticPrompt (y, "To", 8 * stdCharWidth, 0, programFont, 'c');
 
6320
  adp->accns = CreateTagListDialog (x, 3, 3, -1,
 
6321
                                    assmbly_types, assmbly_widths, NULL,
 
6322
                                    ValNodePtrToAssemblyDialog,
 
6323
                                    AssemblyDialogToValNodePtr);
3936
6324
 
3937
6325
  return (DialoG) p;
3938
6326
}
4005
6393
    afp->data = CreateAssemblyDialog (g);
4006
6394
 
4007
6395
    c = HiddenGroup (w, 2, 0, NULL);
4008
 
    b = PushButton (c, "Accept", StdAcceptFormButtonProc);
 
6396
    b = DefaultButton (c, "Accept", StdAcceptFormButtonProc);
4009
6397
    SetObjectExtra (b, afp, NULL);
4010
6398
    PushButton (c, "Cancel", StdCancelButtonProc);
4011
6399
    AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
4117
6505
static SeqIdPtr VisStrDialogToSeqIdSet (DialoG d)
4118
6506
 
4119
6507
{
4120
 
  long          gi;
4121
 
  SeqIdPtr      head = NULL;
4122
 
  ValNodePtr    list;
4123
 
  CharPtr       str;
4124
 
  TextSeqIdPtr  tsip;
4125
 
  ValNodePtr    vnp;
 
6508
  long        gi;
 
6509
  SeqIdPtr    head = NULL;
 
6510
  ValNodePtr  list;
 
6511
  SeqIdPtr    sip;
 
6512
  CharPtr     str;
 
6513
  ValNodePtr  vnp;
4126
6514
 
4127
6515
  if (d == NULL) return NULL;
4128
6516
  list = DialogToPointer (d);
4134
6522
        ValNodeAddInt (&head, SEQID_GI, (Int4) gi);
4135
6523
        */
4136
6524
      } else {
4137
 
        tsip = TextSeqIdNew ();
4138
 
        if (tsip != NULL) {
4139
 
          tsip->accession = StringSaveNoNull (str);
4140
 
          ValNodeAddPointer (&head, SEQID_GENBANK, (Pointer) tsip);
 
6525
        sip = SeqIdFromAccessionDotVersion (str);
 
6526
        if (sip != NULL) {
 
6527
          ValNodeLink (&head, sip);
4141
6528
        }
4142
6529
      }
4143
6530
    }
4187
6574
      case SEQID_GENBANK :
4188
6575
      case SEQID_EMBL :
4189
6576
      case SEQID_DDBJ :
 
6577
      case SEQID_OTHER :
4190
6578
        tsip = (TextSeqIdPtr) sip->data.ptrvalue;
4191
6579
        if (tsip != NULL && (! StringHasNoText (tsip->accession))) {
4192
6580
          StringNCpy_0 (buf, tsip->accession, sizeof (buf));
4483
6871
  AlignObjects (ALIGN_CENTER, (HANDLE) hfp->deleted, (HANDLE) hfp->deleted_date, NULL);
4484
6872
 
4485
6873
  c = HiddenGroup (h, 4, 0, NULL);
4486
 
  b = PushButton (c, "Accept", DoChangeHistory);
 
6874
  b = DefaultButton (c, "Accept", DoChangeHistory);
4487
6875
  SetObjectExtra (b, hfp, NULL);
4488
6876
  PushButton (c, "Cancel", StdCancelButtonProc);
4489
6877
 
4523
6911
  Uint2       entityID;
4524
6912
  Uint2       itemID;
4525
6913
  Uint2       subtype;
 
6914
  Boolean     isDNA;
 
6915
  Boolean     isAlleleGroup;
4526
6916
  Boolean     lastInString;
4527
6917
  Boolean     lastInGroup;
4528
6918
  Boolean     lastInType;
4534
6924
  Int2        numUnknown;
4535
6925
} DefFeatsData, PNTR DefFeatsPtr;
4536
6926
 
4537
 
static Boolean GetMolBioFeatsGatherFunc (GatherContextPtr gcp, Boolean getGene, Boolean getMrna)
 
6927
static Boolean GetMolBioFeatsGatherFunc (GatherContextPtr gcp, Boolean getGene, Boolean getSnoRNA)
4538
6928
 
4539
6929
{
4540
6930
  DefFeatsPtr  dfp;
4544
6934
  Uint1        type;
4545
6935
  ValNodePtr   PNTR vnpp;
4546
6936
 
4547
 
  if (gcp == NULL || gcp->thisitem == NULL || gcp->userdata == NULL) return TRUE;
 
6937
  if (gcp == NULL || gcp->thisitem == NULL || gcp->userdata == NULL)
 
6938
    return TRUE;
4548
6939
  if (gcp->thistype != OBJ_SEQFEAT) return TRUE;
4549
6940
  vnpp = (ValNodePtr PNTR) gcp->userdata;
4550
6941
  sfp = (SeqFeatPtr) gcp->thisitem;
4574
6965
      rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
4575
6966
      if (rrp == NULL) return TRUE;
4576
6967
      switch (rrp->type) {
4577
 
        case 2 :
4578
 
          if (getMrna) {
4579
 
            dfp = MemNew (sizeof (DefFeatsData));
4580
 
            if (dfp == NULL) return TRUE;
4581
 
            dfp->entityID = gcp->entityID;
4582
 
            dfp->itemID = gcp->itemID;
4583
 
            dfp->sfp = sfp;
4584
 
            dfp->subtype = FEATDEF_mRNA;
4585
 
            ValNodeAddPointer (vnpp, 0, (Pointer) dfp);
4586
 
          }
4587
 
          break;
4588
6968
        case 3 :
4589
6969
          dfp = MemNew (sizeof (DefFeatsData));
4590
6970
          if (dfp == NULL) return TRUE;
4603
6983
          dfp->subtype = FEATDEF_rRNA;
4604
6984
          ValNodeAddPointer (vnpp, 0, (Pointer) dfp);
4605
6985
          break;
 
6986
         case 5 :
 
6987
          if (getSnoRNA) {
 
6988
            dfp = MemNew (sizeof (DefFeatsData));
 
6989
            if (dfp == NULL) return TRUE;
 
6990
            dfp->entityID = gcp->entityID;
 
6991
            dfp->itemID = gcp->itemID;
 
6992
            dfp->sfp = sfp;
 
6993
            dfp->subtype = FEATDEF_snRNA;
 
6994
            ValNodeAddPointer (vnpp, 0, (Pointer) dfp);
 
6995
          }
 
6996
          break;
 
6997
       case 7 :
 
6998
          if (getSnoRNA) {
 
6999
            dfp = MemNew (sizeof (DefFeatsData));
 
7000
            if (dfp == NULL) return TRUE;
 
7001
            dfp->entityID = gcp->entityID;
 
7002
            dfp->itemID = gcp->itemID;
 
7003
            dfp->sfp = sfp;
 
7004
            dfp->subtype = FEATDEF_snoRNA;
 
7005
            ValNodeAddPointer (vnpp, 0, (Pointer) dfp);
 
7006
          }
 
7007
          break;
4606
7008
        case 255 :
4607
7009
          if (rrp->ext.choice == 1) {
4608
7010
            str = (CharPtr) rrp->ext.value.ptrvalue;
4656
7058
static Boolean GetGeneCDStRNArRNAGatherFunc (GatherContextPtr gcp)
4657
7059
 
4658
7060
{
4659
 
  return GetMolBioFeatsGatherFunc (gcp, TRUE, FALSE);
4660
 
}
4661
 
 
4662
 
static Boolean GetGeneCDStRNArRNAmRNAGatherFunc (GatherContextPtr gcp)
4663
 
 
4664
 
{
4665
7061
  return GetMolBioFeatsGatherFunc (gcp, TRUE, TRUE);
4666
7062
}
4667
7063
 
4707
7103
  ValNodePtr   vnp1;
4708
7104
  ValNodePtr   vnp2;
4709
7105
 
4710
 
  if (ptr1 != NULL && ptr2 != NULL) {
4711
 
    vnp1 = *((ValNodePtr PNTR) ptr1);
4712
 
    vnp2 = *((ValNodePtr PNTR) ptr2);
4713
 
    if (vnp1 != NULL && vnp2 != NULL) {
4714
 
      dfp1 = (DefFeatsPtr) vnp1->data.ptrvalue;
4715
 
      dfp2 = (DefFeatsPtr) vnp2->data.ptrvalue;
4716
 
      if (dfp1 != NULL && dfp2 != NULL) {
4717
 
        sfp1 = dfp1->sfp;
4718
 
        sfp2 = dfp2->sfp;
4719
 
        if (sfp1 != NULL && sfp2 != NULL) {
4720
 
          bsp1 = GetBioseqGivenSeqLoc (sfp1->location, dfp1->entityID);
4721
 
          bsp2 = GetBioseqGivenSeqLoc (sfp2->location, dfp2->entityID);
4722
 
          if (bsp1 != NULL && bsp2 != NULL) {
4723
 
            leftend1 = GetOffsetInBioseq (sfp1->location, bsp1, SEQLOC_LEFT_END);
4724
 
            leftend2 = GetOffsetInBioseq (sfp2->location, bsp2, SEQLOC_LEFT_END);
4725
 
            rightend1 = GetOffsetInBioseq (sfp1->location, bsp1, SEQLOC_RIGHT_END);
4726
 
            rightend2 = GetOffsetInBioseq (sfp2->location, bsp2, SEQLOC_RIGHT_END);
4727
 
            if (leftend1 > leftend2) {
4728
 
              return 1;
4729
 
            } else if (leftend1 < leftend2) {
4730
 
              return -1;
4731
 
            } else if (sfp2->data.choice == SEQFEAT_GENE) {
4732
 
              return 1;
4733
 
            } else if (sfp1->data.choice == SEQFEAT_GENE) {
4734
 
              return -1;
4735
 
            } else if (rightend1 > rightend2) {
4736
 
              return 1;
4737
 
            } else if (rightend1 < rightend2) {
4738
 
              return -1;
4739
 
            } else {
4740
 
              return 0;
4741
 
            }
4742
 
          }
4743
 
        }
4744
 
      }
4745
 
    }
4746
 
  }
4747
 
  return 0;
 
7106
  /* Check parameters */
 
7107
 
 
7108
  if ((NULL == ptr1) || (NULL == ptr2))
 
7109
    return 0;
 
7110
 
 
7111
  vnp1 = *((ValNodePtr PNTR) ptr1);
 
7112
  vnp2 = *((ValNodePtr PNTR) ptr2);
 
7113
 
 
7114
  if ((NULL == vnp1) || (NULL == vnp2))
 
7115
    return 0;
 
7116
 
 
7117
  /* Get the 2 Seqfeats to compare */
 
7118
 
 
7119
  dfp1 = (DefFeatsPtr) vnp1->data.ptrvalue;
 
7120
  dfp2 = (DefFeatsPtr) vnp2->data.ptrvalue;
 
7121
 
 
7122
  if ((NULL == dfp1) || (NULL == dfp2))
 
7123
    return 0;
 
7124
 
 
7125
  sfp1 = dfp1->sfp;
 
7126
  sfp2 = dfp2->sfp;
 
7127
  
 
7128
  if ((NULL == sfp1) || (NULL == sfp2))
 
7129
    return 0;
 
7130
 
 
7131
  /*
 
7132
  bsp1 = GetBioseqGivenSeqLoc (sfp1->location, dfp1->entityID);
 
7133
  bsp2 = GetBioseqGivenSeqLoc (sfp2->location, dfp2->entityID);
 
7134
  */
 
7135
  bsp1 = BioseqFindFromSeqLoc (sfp1->location);
 
7136
  bsp2 = BioseqFindFromSeqLoc (sfp2->location);
 
7137
 
 
7138
  if ((NULL == bsp1) || (NULL == bsp2))
 
7139
    return 0;
 
7140
 
 
7141
  /* Get the ends of the two Seqfeats, mapped */
 
7142
  /* onto the parent Bioseqs.                 */
 
7143
 
 
7144
  leftend1 = GetOffsetInBioseq (sfp1->location, bsp1, SEQLOC_LEFT_END);
 
7145
  leftend2 = GetOffsetInBioseq (sfp2->location, bsp2, SEQLOC_LEFT_END);
 
7146
  rightend1 = GetOffsetInBioseq (sfp1->location, bsp1, SEQLOC_RIGHT_END);
 
7147
  rightend2 = GetOffsetInBioseq (sfp2->location, bsp2, SEQLOC_RIGHT_END);
 
7148
 
 
7149
  /* Compare the two features and indicate if the first one */
 
7150
  /* is greater (return 1) or the 2nd is (return -1).       */
 
7151
 
 
7152
  if (leftend1 > leftend2)
 
7153
    return 1;
 
7154
  else if (leftend1 < leftend2)
 
7155
    return -1;
 
7156
  else if (sfp2->data.choice == SEQFEAT_GENE)
 
7157
    return 1;
 
7158
  else if (sfp1->data.choice == SEQFEAT_GENE)
 
7159
    return -1;
 
7160
  else if (rightend1 > rightend2)
 
7161
    return 1;
 
7162
  else if (rightend1 < rightend2)
 
7163
    return -1;
 
7164
  else
 
7165
    return 0;
 
7166
 
4748
7167
}
4749
7168
 
4750
7169
static int LIBCALLBACK SortCDSAfterExons (VoidPtr ptr1, VoidPtr ptr2)
4755
7174
  ValNodePtr   vnp1;
4756
7175
  ValNodePtr   vnp2;
4757
7176
 
4758
 
  if (ptr1 != NULL && ptr2 != NULL) {
4759
 
    vnp1 = *((ValNodePtr PNTR) ptr1);
4760
 
    vnp2 = *((ValNodePtr PNTR) ptr2);
4761
 
    if (vnp1 != NULL && vnp2 != NULL) {
4762
 
      dfp1 = (DefFeatsPtr) vnp1->data.ptrvalue;
4763
 
      dfp2 = (DefFeatsPtr) vnp2->data.ptrvalue;
4764
 
      if (dfp1 != NULL && dfp2 != NULL) {
4765
 
        if (dfp1->subtype == FEATDEF_CDS && dfp2->subtype == FEATDEF_exon) {
4766
 
          return 1;
4767
 
        } else if (dfp1->subtype == FEATDEF_exon && dfp2->subtype == FEATDEF_CDS) {
4768
 
          return -1;
4769
 
        } else {
4770
 
          /* return 0; */
4771
 
          return SortCDStRNArRNAByLocation (ptr1, ptr2);
4772
 
        }
4773
 
      }
4774
 
    }
4775
 
  }
4776
 
  return 0;
 
7177
  /* Check parameters */
 
7178
 
 
7179
  if ((NULL == ptr1) || (NULL == ptr2))
 
7180
    return 0;
 
7181
 
 
7182
  vnp1 = *((ValNodePtr PNTR) ptr1);
 
7183
  vnp2 = *((ValNodePtr PNTR) ptr2);
 
7184
  if ((NULL == vnp1) || (NULL == vnp2))
 
7185
    return 0;
 
7186
 
 
7187
  dfp1 = (DefFeatsPtr) vnp1->data.ptrvalue;
 
7188
  dfp2 = (DefFeatsPtr) vnp2->data.ptrvalue;
 
7189
  if ((NULL == dfp1) || (NULL == dfp2))
 
7190
    return 0;
 
7191
 
 
7192
  /* Sort all CDSs after all exons */
 
7193
 
 
7194
  if (dfp1->subtype == FEATDEF_CDS && dfp2->subtype == FEATDEF_exon)
 
7195
    return 1;
 
7196
  else if (dfp1->subtype == FEATDEF_exon && dfp2->subtype == FEATDEF_CDS)
 
7197
    return -1;
 
7198
  else
 
7199
    return SortCDStRNArRNAByLocation (ptr1, ptr2);
 
7200
 
4777
7201
}
4778
7202
 
4779
7203
extern EnumFieldAssoc  orgmod_subtype_alist [];
4780
7204
extern EnumFieldAssoc  subsource_subtype_alist [];
4781
7205
 
4782
7206
static Int2  orgmod_rank [32];
4783
 
static Int2  subsource_rank [26];
 
7207
static Int2  subsource_rank [29];
4784
7208
 
4785
7209
static Boolean StrainAlreadyInParentheses (CharPtr taxname, CharPtr strain)
4786
7210
 
4798
7222
  return TRUE;
4799
7223
}
4800
7224
 
4801
 
static void AddOrgModsToDef (ValNodePtr PNTR stringsPtr, BioSourcePtr biop, Boolean labelMods)
 
7225
static void AddOrgModsToDef (ValNodePtr PNTR stringsPtr,
 
7226
                             BioSourcePtr    biop,
 
7227
                             Boolean         labelMods,
 
7228
                             Boolean         excludeSpOrgs)
4802
7229
 
4803
7230
{
4804
7231
  EnumFieldAssocPtr  ap;
4808
7235
  CharPtr            ptr;
4809
7236
  SubSourcePtr       ssp;
4810
7237
  Char               str [128];
4811
 
  Char               text [64];
 
7238
  Char               text [TEXT_MAX_LEN];
4812
7239
 
4813
7240
  if (stringsPtr != NULL && biop != NULL) {
4814
7241
    orp = biop->org;
4818
7245
        mod = onp->mod;
4819
7246
        while (mod != NULL) {
4820
7247
          if (mod->subtype < 32 && orgmod_rank [mod->subtype] > 0) {
4821
 
            if (mod->subtype == 2 && StrainAlreadyInParentheses (orp->taxname, mod->subname)) {
4822
 
              /* do not add strain if already parenthetical in organism name */
 
7248
            if (mod->subtype == 2 &&
 
7249
                StrainAlreadyInParentheses (orp->taxname, mod->subname)) {
 
7250
              /* do not add strain if already parenthetical in org name */
 
7251
            } else if ((TRUE == excludeSpOrgs) &&
 
7252
                       (StringStr (orp->taxname," sp.") != NULL)) {
4823
7253
            } else {
4824
7254
              text [0] = '\0';
4825
7255
              str [0] = '\0';
4826
 
              StringNCpy_0 (text, mod->subname, sizeof (text));
 
7256
              StringNCpy_0 (text, mod->subname, TEXT_MAX_LEN);
4827
7257
              for (ap = orgmod_subtype_alist; ap->name != NULL; ap++) {
4828
7258
                if (ap->value == mod->subtype) {
4829
7259
                  StringNCpy_0 (str, ap->name, sizeof (str));
4830
7260
                }
4831
7261
              }
4832
 
              LabelAModifier (str, text, labelMods);
 
7262
              if (mod->subtype == ORGMOD_nat_host) {
 
7263
                StringCpy (str, "from");
 
7264
              }
 
7265
              LabelAModifier (str, text, labelMods || mod->subtype == ORGMOD_nat_host);
4833
7266
              if (! StringHasNoText (str)) {
4834
7267
                ValNodeCopyStr (stringsPtr, orgmod_rank [mod->subtype], str);
4835
7268
              }
4842
7275
 
4843
7276
    ssp = biop->subtype;
4844
7277
    while (ssp != NULL) {
4845
 
      if (ssp->subtype < 26 && subsource_rank [ssp->subtype] > 0) {
4846
 
        text [0] = '\0';
4847
 
        str [0] = '\0';
4848
 
        StringNCpy_0 (text, ssp->name, sizeof (text));
4849
 
        for (ap = subsource_subtype_alist; ap->name != NULL; ap++) {
4850
 
          if (ap->value == ssp->subtype) {
4851
 
            StringNCpy_0 (str, ap->name, sizeof (str));
4852
 
            ptr = StringStr (str, "-name");
4853
 
            if (ptr != NULL) {
4854
 
              *ptr = '\0';
4855
 
            }
4856
 
            if (ssp->subtype == 23) { /* country */
4857
 
              ptr = StringStr (text, ":");
4858
 
              if (ptr != NULL) {
4859
 
                *ptr = '\0';
4860
 
              }
4861
 
            }
4862
 
          }
4863
 
        }
4864
 
        if (ssp->subtype == 23 /* && (! labelMods) */) {
4865
 
          StringCpy (str, "from");
4866
 
        }
4867
 
        LabelAModifier (str, text, labelMods || (ssp->subtype == 23));
4868
 
        if (! StringHasNoText (str)) {
4869
 
          ValNodeCopyStr (stringsPtr, subsource_rank [ssp->subtype], str);
4870
 
        }
 
7278
      if (ssp->subtype < 29 &&
 
7279
          subsource_rank [ssp->subtype] > 0 &&
 
7280
          ssp->subtype != SUBSRC_transgenic) {
 
7281
        if ((TRUE == excludeSpOrgs) &&
 
7282
            (StringStr (orp->taxname," sp.") != NULL)) {
 
7283
        } else {
 
7284
          text [0] = '\0';
 
7285
          str [0] = '\0';
 
7286
          StringNCpy_0 (text, ssp->name, TEXT_MAX_LEN);
 
7287
          for (ap = subsource_subtype_alist; ap->name != NULL; ap++) {
 
7288
            if (ap->value == ssp->subtype) {
 
7289
              StringNCpy_0 (str, ap->name, TEXT_MAX_LEN);
 
7290
              ptr = StringStr (str, "-name");
 
7291
              if (ptr != NULL) {
 
7292
                *ptr = '\0';
 
7293
              }
 
7294
              if (ssp->subtype == SUBSRC_country) { /* country */
 
7295
                ptr = StringStr (text, ":");
 
7296
                if (ptr != NULL) {
 
7297
                  *ptr = '\0';
 
7298
                }
 
7299
              }
 
7300
            }
 
7301
          }
 
7302
          if (ssp->subtype == SUBSRC_country /* && (! labelMods) */) {
 
7303
            StringCpy (str, "from");
 
7304
          }
 
7305
          if (ssp->subtype == SUBSRC_lab_host /* && (! labelMods) */) {
 
7306
            StringCpy (str, "from");
 
7307
          }
 
7308
          LabelAModifier (str, text, labelMods || ssp->subtype == SUBSRC_country || ssp->subtype == SUBSRC_lab_host);
 
7309
          if (! StringHasNoText (str)) {
 
7310
            ValNodeCopyStr (stringsPtr, subsource_rank [ssp->subtype], str);
 
7311
          }
 
7312
        }
4871
7313
      }
4872
7314
      ssp = ssp->next;
4873
7315
    }
4938
7380
  NULL
4939
7381
};
4940
7382
 
4941
 
static void FinishAutoDefProc (Uint2 entityID, SeqEntryPtr sep,
4942
 
                               ValNodePtr head, BioseqPtr target,
4943
 
                               SeqEntryPtr nsep, MolInfoPtr mip,
4944
 
                               ValNodePtr strings, BioSourcePtr biop,
4945
 
                               Int2 mitochloroflag)
4946
 
 
4947
 
{
4948
 
  Int2          count;
 
7383
/*---------------------------------------------------------------------*/
 
7384
/*                                                                     */
 
7385
/* AutoDef_AddProtein () -- Add a protein feature to a defline.        */
 
7386
/*                                                                     */
 
7387
/*---------------------------------------------------------------------*/
 
7388
 
 
7389
static void AutoDef_AddProtein (DefFeatsPtr dfp,
 
7390
                                MolInfoPtr  mip,
 
7391
                                CharPtr     str,
 
7392
                                Int2        featNum)
 
7393
{
 
7394
  Char    text [64];
 
7395
  CharPtr ptr;
 
7396
 
 
7397
  /* If we're suppressing the prefix then */
 
7398
  /* skip all the rest.                   */
 
7399
 
 
7400
  if (dfp->suppressprefix) {
 
7401
    str [0] = '\0';
 
7402
    if (dfp->sfp->partial)
 
7403
      StringCat (str, "partial cds");
 
7404
    else
 
7405
      StringCat (str, "complete cds");
 
7406
 
 
7407
    if (dfp->altSplices > 1)
 
7408
      StringCat (str, ", alternatively spliced");
 
7409
 
 
7410
    return;
 
7411
  }
 
7412
 
 
7413
  /* If we have no protein name, we're done */
 
7414
 
 
7415
  if (dfp->protname == NULL)
 
7416
    return;
 
7417
 
 
7418
  /* Add the protein name and, if there */
 
7419
  /* is one, the gene name.             */
 
7420
 
 
7421
  if (StringICmp (dfp->protname, "unknown") == 0 &&
 
7422
      !(StringHasNoText (dfp->genename))) {
 
7423
    StringNCpy_0 (text, dfp->genename, DEFLINE_MAX_GENENAME_LEN);
 
7424
    StringCat (str, text);
 
7425
  }
 
7426
  else {
 
7427
    StringNCpy_0 (str, dfp->protname, DEFLINE_MAX_LEN - 100);
 
7428
    if (dfp->genename != NULL) {
 
7429
      StringNCpy_0 (text, dfp->genename, DEFLINE_MAX_GENENAME_LEN);
 
7430
      if (! StringHasNoText (text)) {
 
7431
        StringCat (str, " (");
 
7432
        StringCat (str, text);
 
7433
        StringCat (str, ")");
 
7434
      }
 
7435
    }
 
7436
  }
 
7437
 
 
7438
  if (dfp->lastInGroup || dfp->lastInType) {
 
7439
 
 
7440
    if (mip != NULL) {
 
7441
      ptr = StringISearch (str, "precursor");
 
7442
      if (ptr != NULL && StringICmp (ptr, "precursor") == 0) {
 
7443
        StringCat (str, ",");
 
7444
      }
 
7445
      if (mip->biomol == MOLECULE_TYPE_MRNA) {
 
7446
        StringCat (str, " mRNA");
 
7447
      } else if (mip->biomol == MOLECULE_TYPE_PRE_MRNA) {
 
7448
        StringCat (str, " precursor RNA");
 
7449
      } else {
 
7450
        StringCat (str, " gene");
 
7451
      }
 
7452
    }
 
7453
 
 
7454
    if (featNum > 1)
 
7455
      StringCat (str, "s");
 
7456
    else if (! StringHasNoText (dfp->allelename)) {
 
7457
      StringNCpy_0 (text, dfp->allelename, TEXT_MAX_LEN);
 
7458
      StringCat (str, ", ");
 
7459
      StringCat (str, text);
 
7460
      StringCat (str, " allele");
 
7461
    }
 
7462
 
 
7463
    if (!dfp->isAlleleGroup)
 
7464
    {
 
7465
      if (dfp->sfp->partial)
 
7466
        StringCat (str, ", partial cds");
 
7467
      else 
 
7468
        StringCat (str, ", complete cds");
 
7469
    }
 
7470
    
 
7471
    if (dfp->altSplices > 1)
 
7472
      StringCat (str, ", alternatively spliced");
 
7473
 
 
7474
  }
 
7475
 
 
7476
}
 
7477
 
 
7478
/*---------------------------------------------------------------------*/
 
7479
/*                                                                     */
 
7480
/* AutoDef_AddGene () -- Add a Gene feature to a defline.              */
 
7481
/*                                                                     */
 
7482
/*---------------------------------------------------------------------*/
 
7483
 
 
7484
static void AutoDef_AddGene (DefFeatsPtr dfp,
 
7485
                             CharPtr     str,
 
7486
                             Int2        featNum,
 
7487
                             CharPtr     text,
 
7488
                             MolInfoPtr  mip)
 
7489
{
 
7490
  if (dfp->genename != NULL)
 
7491
    StringNCpy_0 (str, dfp->genename, DEFLINE_MAX_GENENAME_LEN);
 
7492
  if (dfp->lastInGroup || dfp->lastInType) {
 
7493
    if (mip != NULL) {
 
7494
      if (mip->biomol == MOLECULE_TYPE_MRNA)
 
7495
        StringCat (str, " mRNA");
 
7496
      else if (mip->biomol == MOLECULE_TYPE_PRE_MRNA)
 
7497
        StringCat (str, " precursor RNA");
 
7498
      else
 
7499
        StringCat (str, " gene");
 
7500
    }
 
7501
    else
 
7502
      StringCat (str, " gene");
 
7503
    if (featNum > 1)
 
7504
      StringCat (str, "s");
 
7505
    if (featNum < 2 && (! StringHasNoText (dfp->allelename))) {
 
7506
      StringNCpy_0 (text, dfp->allelename, TEXT_MAX_LEN);
 
7507
      StringCat (str, ", ");
 
7508
      StringCat (str, text);
 
7509
      StringCat (str, " allele");
 
7510
    }
 
7511
    if (dfp->sfp->partial)
 
7512
      StringCat (str, ", partial sequence");
 
7513
    else
 
7514
      StringCat (str, ", complete sequence");
 
7515
  }
 
7516
}
 
7517
 
 
7518
/*---------------------------------------------------------------------*/
 
7519
/*                                                                     */
 
7520
/* AutoDef_AddRRNAandOtherRNA () -- Add an rRNA or other RNA feature   */
 
7521
/*                                  to a defline.                      */
 
7522
/*                                                                     */
 
7523
/*---------------------------------------------------------------------*/
 
7524
 
 
7525
static void AutoDef_AddRRNAandOtherRNA (DefFeatsPtr dfp,
 
7526
                                        CharPtr     str,
 
7527
                                        Int2        featNum,
 
7528
                                        CharPtr     text,
 
7529
                                        MolInfoPtr  mip)
 
7530
{
 
7531
  RnaRefPtr  rrp;
 
7532
  CharPtr    ptr;
 
7533
 
 
7534
  rrp = (RnaRefPtr) dfp->sfp->data.value.ptrvalue;
 
7535
  if (rrp != NULL) {
 
7536
    if (rrp->ext.choice == 1) {
 
7537
      StringNCpy_0 (str, (CharPtr) rrp->ext.value.ptrvalue,
 
7538
                    DEFLINE_MAX_LEN - 50);
 
7539
      if (dfp->subtype == FEATDEF_rRNA) {
 
7540
        ptr = StringISearch (str, " rRNA");
 
7541
        if (ptr != NULL)
 
7542
          *ptr = '\0';
 
7543
        ptr = StringISearch (str, " ribosomal RNA");
 
7544
        if (ptr != NULL)
 
7545
          *ptr = '\0';
 
7546
        if (! StringHasNoText (str))
 
7547
          StringCat (str, " ribosomal RNA");
 
7548
      }
 
7549
      else if (dfp->subtype == FEATDEF_otherRNA) {
 
7550
      }
 
7551
      if (dfp->genename != NULL) {
 
7552
        StringNCpy_0 (text, dfp->genename, DEFLINE_MAX_GENENAME_LEN);
 
7553
        if (! StringHasNoText (text)) {
 
7554
          StringCat (str, " (");
 
7555
          StringCat (str, text);
 
7556
          StringCat (str, ")");
 
7557
        }
 
7558
      }
 
7559
      if (dfp->lastInString || dfp->lastInGroup || dfp->lastInType) {
 
7560
        if (dfp->subtype == FEATDEF_rRNA &&
 
7561
            mip->biomol == MOLECULE_TYPE_GENOMIC) {
 
7562
          StringCat (str, " gene");
 
7563
          if (featNum > 1)
 
7564
            StringCat (str, "s");
 
7565
        }
 
7566
      }
 
7567
      if (dfp->lastInGroup || dfp->lastInType) {
 
7568
        if (dfp->sfp->partial)
 
7569
          StringCat (str, ", partial sequence");
 
7570
        else
 
7571
          StringCat (str, ", complete sequence");
 
7572
      }
 
7573
    }
 
7574
  }
 
7575
}
 
7576
 
 
7577
/*---------------------------------------------------------------------*/
 
7578
/*                                                                     */
 
7579
/* AutoDef_AddtRNA () -- Add a tRNA feature to a defline.              */
 
7580
/*                                                                     */
 
7581
/*---------------------------------------------------------------------*/
 
7582
 
 
7583
static void AutoDef_AddtRNA (DefFeatsPtr dfp,
 
7584
                             CharPtr     str,
 
7585
                             Int2        featNum,
 
7586
                             CharPtr     text)
 
7587
{
 
7588
  RnaRefPtr  rrp;
 
7589
  tRNAPtr    trna;
 
7590
 
 
7591
  rrp = (RnaRefPtr) dfp->sfp->data.value.ptrvalue;
 
7592
  if (rrp != NULL) {
 
7593
    if (rrp->ext.choice == 2) {
 
7594
      trna = rrp->ext.value.ptrvalue;
 
7595
      if (trna != NULL) {
 
7596
        if (FeatDefLabel (dfp->sfp, str, DEFLINE_MAX_LEN - 2,
 
7597
                          OM_LABEL_CONTENT) > 0) {
 
7598
          if (dfp->genename != NULL) {
 
7599
            StringNCpy_0 (text, dfp->genename,
 
7600
                          DEFLINE_MAX_GENENAME_LEN);
 
7601
            if (! StringHasNoText (text)) {
 
7602
              StringCat (str, " (");
 
7603
              StringCat (str, text);
 
7604
              StringCat (str, ")");
 
7605
            }
 
7606
          }
 
7607
          if (dfp->lastInGroup || dfp->lastInType) {
 
7608
            StringCat (str, " gene");
 
7609
            if (featNum > 1)
 
7610
              StringCat (str, "s");
 
7611
            if (dfp->sfp->partial)
 
7612
              StringCat (str, ", partial sequence");
 
7613
            else
 
7614
              StringCat (str, ", complete sequence");
 
7615
          }
 
7616
        }
 
7617
      }
 
7618
    }
 
7619
  }
 
7620
}
 
7621
 
 
7622
/*---------------------------------------------------------------------*/
 
7623
/*                                                                     */
 
7624
/* AutoDef_AddsnRNA () -- Add a snRNA feature to a defline.            */
 
7625
/*                                                                     */
 
7626
/*---------------------------------------------------------------------*/
 
7627
 
 
7628
static void AutoDef_AddsnRNA (DefFeatsPtr dfp,
 
7629
                              CharPtr     str,
 
7630
                              Int2        featNum,
 
7631
                              CharPtr     text,
 
7632
                              MolInfoPtr  mip)
 
7633
{
 
7634
  RnaRefPtr  rrp;
 
7635
 
 
7636
  rrp = (RnaRefPtr) dfp->sfp->data.value.ptrvalue;
 
7637
  if (rrp != NULL) {
 
7638
    if (rrp->ext.choice == 1) {
 
7639
      StringNCpy_0 (str, (CharPtr) rrp->ext.value.ptrvalue, DEFLINE_MAX_LEN);
 
7640
      if (! StringHasNoText (str)) {
 
7641
        if (dfp->genename != NULL) {
 
7642
          StringNCpy_0 (text, dfp->genename,
 
7643
                        DEFLINE_MAX_GENENAME_LEN);
 
7644
          if (! StringHasNoText (text)) {
 
7645
            StringCat (str, " (");
 
7646
            StringCat (str, text);
 
7647
            StringCat (str, ")");
 
7648
          }
 
7649
        }
 
7650
        if (dfp->lastInGroup || dfp->lastInType) {
 
7651
          if (mip == NULL || mip->biomol != MOLECULE_TYPE_SNRNA) {
 
7652
            StringCat (str, " gene");
 
7653
            if (featNum > 1)
 
7654
              StringCat (str, "s");
 
7655
          }
 
7656
          if (dfp->sfp->partial)
 
7657
            StringCat (str, ", partial sequence");
 
7658
          else
 
7659
            StringCat (str, ", complete sequence");
 
7660
        }
 
7661
      }
 
7662
    }
 
7663
  }
 
7664
}
 
7665
 
 
7666
/*---------------------------------------------------------------------*/
 
7667
/*                                                                     */
 
7668
/* AutoDef_AddsnoRNA () -- Add a snoRNA feature to a defline.          */
 
7669
/*                                                                     */
 
7670
/*---------------------------------------------------------------------*/
 
7671
 
 
7672
static void AutoDef_AddsnoRNA (DefFeatsPtr dfp,
 
7673
                               CharPtr     str,
 
7674
                               Int2        featNum,
 
7675
                               CharPtr     text,
 
7676
                               MolInfoPtr  mip)
 
7677
{
 
7678
  RnaRefPtr  rrp;
 
7679
 
 
7680
  rrp = (RnaRefPtr) dfp->sfp->data.value.ptrvalue;
 
7681
  if (rrp != NULL) {
 
7682
    if (rrp->ext.choice == 1) {
 
7683
      StringNCpy_0 (str, (CharPtr) rrp->ext.value.ptrvalue, DEFLINE_MAX_LEN);
 
7684
      if (! StringHasNoText (str)) {
 
7685
        if (dfp->genename != NULL) {
 
7686
          StringNCpy_0 (text, dfp->genename,
 
7687
                        DEFLINE_MAX_GENENAME_LEN);
 
7688
          if (! StringHasNoText (text)) {
 
7689
            StringCat (str, " (");
 
7690
            StringCat (str, text);
 
7691
            StringCat (str, ")");
 
7692
          }
 
7693
        }
 
7694
        if (dfp->lastInGroup || dfp->lastInType) {
 
7695
          if (mip == NULL || mip->biomol != MOLECULE_TYPE_SNORNA) {
 
7696
            StringCat (str, " gene");
 
7697
            if (featNum > 1)
 
7698
              StringCat (str, "s");
 
7699
          }
 
7700
          if (dfp->sfp->partial)
 
7701
            StringCat (str, ", partial sequence");
 
7702
          else
 
7703
            StringCat (str, ", complete sequence");
 
7704
        }
 
7705
      }
 
7706
    }
 
7707
  }
 
7708
}
 
7709
 
 
7710
/*---------------------------------------------------------------------*/
 
7711
/*                                                                     */
 
7712
/* AutoDef_AddmRNA () -- Add an mRNA feature to a defline.             */
 
7713
/*                                                                     */
 
7714
/*---------------------------------------------------------------------*/
 
7715
 
 
7716
static void AutoDef_AddmRNA (DefFeatsPtr dfp,
 
7717
                             CharPtr     str,
 
7718
                             Int2        featNum,
 
7719
                             CharPtr     text,
 
7720
                             MolInfoPtr  mip)
 
7721
{
 
7722
  CharPtr  ptr;
 
7723
 
 
7724
  StringNCpy_0 (str, dfp->genename, DEFLINE_MAX_GENENAME_LEN);
 
7725
  if (dfp->lastInGroup || dfp->lastInType) {
 
7726
    if (mip != NULL) {
 
7727
      ptr = StringISearch (str, "precursor");
 
7728
      if (ptr != NULL && StringICmp (ptr, "precursor") == 0)
 
7729
        StringCat (str, ",");
 
7730
      if (mip->biomol == MOLECULE_TYPE_MRNA)
 
7731
        StringCat (str, " mRNA");
 
7732
      else if (mip->biomol == MOLECULE_TYPE_PRE_MRNA)
 
7733
        StringCat (str, " precursor RNA");
 
7734
      else
 
7735
        StringCat (str, " gene");
 
7736
    }
 
7737
    if (featNum > 1)
 
7738
      StringCat (str, "s");
 
7739
    if (featNum < 2 && (! StringHasNoText (dfp->allelename))) {
 
7740
      StringNCpy_0 (text, dfp->allelename, TEXT_MAX_LEN);
 
7741
      StringCat (str, ", ");
 
7742
      StringCat (str, text);
 
7743
      StringCat (str, " allele");
 
7744
    }
 
7745
    if (dfp->sfp->partial)
 
7746
      StringCat (str, ", partial cds");
 
7747
    else
 
7748
      StringCat (str, ", complete cds");
 
7749
  }
 
7750
}
 
7751
 
 
7752
/*---------------------------------------------------------------------*/
 
7753
/*                                                                     */
 
7754
/* AutoDef_AddPseudoGene () -- Add a pseudogene feature to a defline.  */
 
7755
/*                                                                     */
 
7756
/*---------------------------------------------------------------------*/
 
7757
 
 
7758
static void AutoDef_AddPseudoGene (DefFeatsPtr dfp,
 
7759
                                   CharPtr     str,
 
7760
                                   Int2        featNum,
 
7761
                                   CharPtr     text)
 
7762
{
 
7763
  if (dfp->genename != NULL)
 
7764
    StringNCpy_0 (str, dfp->genename, DEFLINE_MAX_GENENAME_LEN);
 
7765
 
 
7766
  if (dfp->lastInGroup || dfp->lastInType) {
 
7767
    StringCat (str, " pseudogene");
 
7768
    if (featNum > 1) {
 
7769
      StringCat (str, "s");
 
7770
    }
 
7771
    if (featNum < 2 && (! StringHasNoText (dfp->allelename))) {
 
7772
      StringNCpy_0 (text, dfp->allelename, TEXT_MAX_LEN);
 
7773
      StringCat (str, ", ");
 
7774
      StringCat (str, text);
 
7775
      StringCat (str, " allele");
 
7776
    }
 
7777
    if (dfp->sfp->partial) {
 
7778
      StringCat (str, ", partial sequence");
 
7779
    } else {
 
7780
      StringCat (str, ", complete sequence");
 
7781
    }
 
7782
  }
 
7783
}
 
7784
 
 
7785
/*---------------------------------------------------------------------*/
 
7786
/*                                                                     */
 
7787
/* AutoDef_AddUnknown () -- Add an unknown feature to a defline.       */
 
7788
/*                                                                     */
 
7789
/*---------------------------------------------------------------------*/
 
7790
 
 
7791
static void AutoDef_AddUnknown (DefFeatsPtr dfp,
 
7792
                                CharPtr     str,
 
7793
                                MolInfoPtr  mip)
 
7794
{
 
7795
  if (mip != NULL && mip->biomol == MOLECULE_TYPE_MRNA)
 
7796
    StringCat (str, "unknown mRNA");
 
7797
  else if (mip->biomol == MOLECULE_TYPE_PRE_MRNA)
 
7798
    StringCat (str, " unknown precursor RNA");
 
7799
  else
 
7800
    StringCat (str, "unknown gene");
 
7801
  if (dfp->numUnknown > 1) {
 
7802
    StringCat (str, "s");
 
7803
  }
 
7804
}
 
7805
 
 
7806
/*---------------------------------------------------------------------*/
 
7807
/*                                                                     */
 
7808
/* AutoDef_AddLTR () -- Add a Long Terminal Repeat feature to          */
 
7809
/*                      a defline.                                     */
 
7810
/*                                                                     */
 
7811
/*---------------------------------------------------------------------*/
 
7812
 
 
7813
static void AutoDef_AddLTR (DefFeatsPtr dfp,
 
7814
                            CharPtr     str,
 
7815
                            SeqFeatPtr  sfp)
 
7816
{
 
7817
  CharPtr  ptr;
 
7818
 
 
7819
  if (! StringHasNoText (sfp->comment)) {
 
7820
    StringNCpy_0 (str, sfp->comment, DEFLINE_MAX_LEN);
 
7821
    ptr = StringISearch (str, " long terminal repeat");
 
7822
    if (ptr != NULL)
 
7823
      *ptr = '\0';
 
7824
    ptr = StringISearch (str, " long terminal repeat");
 
7825
    if (ptr != NULL)
 
7826
      *ptr = '\0';
 
7827
    if (! StringHasNoText (str))
 
7828
      StringCat (str, " long terminal repeat");
 
7829
  }
 
7830
  else
 
7831
    StringCpy (str, "long terminal repeat");
 
7832
 
 
7833
  if (dfp->lastInGroup || dfp->lastInType) {
 
7834
    if (dfp->sfp->partial)
 
7835
      StringCat (str, ", partial sequence");
 
7836
    else
 
7837
      StringCat (str, ", complete sequence");
 
7838
  }
 
7839
}
 
7840
 
 
7841
/*---------------------------------------------------------------------*/
 
7842
/*                                                                     */
 
7843
/* AutoDef_AddExon () -- Add an exon feature to a defline.             */
 
7844
/*                                                                     */
 
7845
/*---------------------------------------------------------------------*/
 
7846
 
 
7847
static void AutoDef_AddExon (DefFeatsPtr dfp,
 
7848
                             CharPtr     str,
 
7849
                             CharPtr     text,
 
7850
                             ValNodePtr  vnp,
 
7851
                             SeqFeatPtr  sfp,
 
7852
                             MolInfoPtr  mip)
 
7853
{
 
7854
  CharPtr       exonnumber;
 
7855
 
 
7856
  /* If there is a protein name then use it*/
 
7857
 
 
7858
  if (dfp->protname != NULL) {
 
7859
    str [0] = '\0';
 
7860
 
 
7861
    /* Add the protein name and, if there */
 
7862
    /* is one, the gene name.             */
 
7863
 
 
7864
    if (! dfp->suppressprefix) {
 
7865
      StringNCpy_0 (str, dfp->protname, DEFLINE_MAX_LEN - 100);
 
7866
      if (dfp->genename != NULL) {
 
7867
        StringNCpy_0 (text, dfp->genename, DEFLINE_MAX_GENENAME_LEN);
 
7868
        if (! StringHasNoText (text)) {
 
7869
          StringCat (str, " (");
 
7870
          StringCat (str, text);
 
7871
          StringCat (str, ") gene,");
 
7872
          if (! StringHasNoText (dfp->allelename)) {
 
7873
            StringNCpy_0 (text, dfp->allelename, TEXT_MAX_LEN);
 
7874
            StringCat (str, " ");
 
7875
            StringCat (str, text);
 
7876
            StringCat (str, " allele,");
 
7877
          }
 
7878
        }
 
7879
      }
 
7880
      else if (MOLECULE_TYPE_GENOMIC == mip->biomol)
 
7881
        StringCat (str, " gene,");
 
7882
    }
 
7883
 
 
7884
    /* Add the exon number */
 
7885
 
 
7886
    if ((! StringHasNoText (str)) || dfp->suppressprefix) {
 
7887
      exonnumber = GetExonNumber (sfp->qual);
 
7888
      if (! dfp->suppressprefix) {
 
7889
        if (exonnumber == NULL) {
 
7890
          if (StringStr (sfp->comment, "exon") != NULL &&
 
7891
              (! NextIsExon (vnp))) {
 
7892
          } else {
 
7893
            StringCat (str, " exon");
 
7894
            if (NextIsExon (vnp)) {
 
7895
              StringCat (str, "s");
 
7896
            }
 
7897
          }
 
7898
        } else {
 
7899
          StringCat (str, " exon");
 
7900
          if (NextIsExon (vnp)) {
 
7901
            StringCat (str, "s");
 
7902
          }
 
7903
        }
 
7904
      }
 
7905
      if (exonnumber != NULL) {
 
7906
        if (! dfp->suppressprefix) {
 
7907
          StringCat (str, " ");
 
7908
        }
 
7909
        StringCat (str, exonnumber);
 
7910
      } else {
 
7911
        if (! StringHasNoText (sfp->comment)) {
 
7912
          if (! dfp->suppressprefix) {
 
7913
            StringCat (str, " ");
 
7914
          }
 
7915
          StringCat (str, sfp->comment);
 
7916
        }
 
7917
      }
 
7918
    }
 
7919
  }
 
7920
 
 
7921
  /* Else use the gene name if there is one */
 
7922
 
 
7923
  else if (dfp->genename != NULL) {
 
7924
    str [0] = '\0';
 
7925
 
 
7926
    /* Add the gene name */
 
7927
 
 
7928
    if (! dfp->suppressprefix) {
 
7929
      StringNCpy_0 (str, dfp->genename, DEFLINE_MAX_GENENAME_LEN);
 
7930
      StringCat (str, " gene,");
 
7931
    }
 
7932
 
 
7933
    /* Add the exon number */
 
7934
 
 
7935
    if ((! StringHasNoText (str)) || dfp->suppressprefix) {
 
7936
      exonnumber = GetExonNumber (sfp->qual);
 
7937
      if (! dfp->suppressprefix) {
 
7938
        if (exonnumber == NULL) {
 
7939
          if (StringStr (sfp->comment, "exon") != NULL &&
 
7940
              (! NextIsExon (vnp))) {
 
7941
          } else {
 
7942
            StringCat (str, " exon");
 
7943
            if (NextIsExon (vnp)) {
 
7944
              StringCat (str, "s");
 
7945
            }
 
7946
          }
 
7947
        } else {
 
7948
          StringCat (str, " exon");
 
7949
          if (NextIsExon (vnp)) {
 
7950
            StringCat (str, "s");
 
7951
          }
 
7952
        }
 
7953
      }
 
7954
      if (exonnumber != NULL) {
 
7955
        if (! dfp->suppressprefix) {
 
7956
          StringCat (str, " ");
 
7957
        }
 
7958
        StringCat (str, exonnumber);
 
7959
      } else {
 
7960
        if (! StringHasNoText (sfp->comment)) {
 
7961
          if (! dfp->suppressprefix) {
 
7962
            StringCat (str, " ");
 
7963
          }
 
7964
          StringCat (str, sfp->comment);
 
7965
        }
 
7966
      }
 
7967
    }
 
7968
  }
 
7969
 
 
7970
  /* Otherwise, label it as uncharacterized */
 
7971
 
 
7972
  else
 
7973
    StringCpy (str, "uncharacterized exon");
 
7974
 
 
7975
}
 
7976
 
 
7977
/*---------------------------------------------------------------------*/
 
7978
/*                                                                     */
 
7979
/* AutoDef_AddSeparator () -- Add a separator before two features.     */
 
7980
/*                                                                     */
 
7981
/*---------------------------------------------------------------------*/
 
7982
 
 
7983
static void AutoDef_AddSeparator (DefFeatsPtr dfp,
 
7984
                                  CharPtr     str,
 
7985
                                  ValNodePtr  vnp,
 
7986
                                  Int2        featNum)
 
7987
{
 
7988
  DefFeatsPtr   nextdfp;
 
7989
 
 
7990
  nextdfp = (DefFeatsPtr) vnp->data.ptrvalue;
 
7991
  if (dfp->lastInPenultimate) {
 
7992
    if ((dfp->subtype == FEATDEF_rRNA &&
 
7993
         nextdfp->subtype == FEATDEF_otherRNA &&
 
7994
         dfp->sfp->partial == nextdfp->sfp->partial) ||
 
7995
        (dfp->subtype == FEATDEF_otherRNA &&
 
7996
         nextdfp->subtype == FEATDEF_rRNA &&
 
7997
         dfp->sfp->partial == nextdfp->sfp->partial)) 
 
7998
      StringCat (str, ", and");
 
7999
    else if (dfp->subtype == FEATDEF_exon &&
 
8000
             nextdfp->subtype == FEATDEF_exon)
 
8001
      StringCat (str, ",");
 
8002
    else
 
8003
      StringCat (str, "; and");
 
8004
  }
 
8005
  else if (dfp->lastInType || dfp->lastInGroup)
 
8006
    StringCat (str, ";");
 
8007
  else if (nextdfp->lastInType || nextdfp->lastInGroup) {
 
8008
    if (featNum > 1)
 
8009
      StringCat (str, ", and");
 
8010
    else
 
8011
      StringCat (str, " and");
 
8012
  }
 
8013
  else
 
8014
    StringCat (str, ",");
 
8015
}
 
8016
/*---------------------------------------------------------------------*/
 
8017
/*                                                                     */
 
8018
/* AutoDef_AddPenultSeparator () -- Add a separator before the last    */
 
8019
/*                                  feature.                           */
 
8020
/*                                                                     */
 
8021
/*---------------------------------------------------------------------*/
 
8022
 
 
8023
static void AutoDef_AddPenultSeparator (DefFeatsPtr dfp,
 
8024
                                        CharPtr     str,
 
8025
                                        ValNodePtr  vnp,
 
8026
                                        Int2        featNum)
 
8027
{
 
8028
  DefFeatsPtr   nextdfp;
 
8029
 
 
8030
  nextdfp = (DefFeatsPtr) vnp->data.ptrvalue;
 
8031
  if (dfp->lastInPenultimate) {
 
8032
    if ((dfp->subtype == FEATDEF_rRNA &&
 
8033
         nextdfp->subtype == FEATDEF_otherRNA &&
 
8034
         dfp->sfp->partial == nextdfp->sfp->partial) ||
 
8035
        (dfp->subtype == FEATDEF_otherRNA &&
 
8036
         nextdfp->subtype == FEATDEF_rRNA &&
 
8037
         dfp->sfp->partial == nextdfp->sfp->partial))
 
8038
      StringCat (str, ", and");
 
8039
    else if (dfp->subtype == FEATDEF_exon &&
 
8040
             nextdfp->subtype == FEATDEF_exon)
 
8041
      StringCat (str, " and");
 
8042
    else
 
8043
      StringCat (str, "; and");
 
8044
  }
 
8045
  else if (dfp->lastInType || dfp->lastInGroup) {
 
8046
    if (featNum > 1)
 
8047
      StringCat (str, ", and");
 
8048
    else
 
8049
      StringCat (str, " and");
 
8050
  }
 
8051
  else if (nextdfp->lastInType || nextdfp->lastInGroup) {
 
8052
    if (featNum > 1)
 
8053
      StringCat (str, ", and");
 
8054
    else
 
8055
      StringCat (str, " and");
 
8056
  }
 
8057
  else {
 
8058
    if (featNum > 1)
 
8059
      StringCat (str, ", and");
 
8060
    else
 
8061
      StringCat (str, " and");
 
8062
  }
 
8063
}
 
8064
 
 
8065
/*---------------------------------------------------------------------*/
 
8066
/*                                                                     */
 
8067
/* AutoDef_AddEnding () -- Add an ending on to the definition line     */
 
8068
/*                         after the last feature.                     */
 
8069
/*                                                                     */
 
8070
/*---------------------------------------------------------------------*/
 
8071
 
 
8072
static void AutoDef_AddEnding (CharPtr      str,
 
8073
                               BioSourcePtr biop,
 
8074
                               Int2         mitocount,
 
8075
                               Int2         mitochloroflag)
 
8076
{
 
8077
  Char orgnelle [80];
 
8078
 
 
8079
  if (biop != NULL) {
 
8080
    orgnelle [0] = '\0';
 
8081
    switch (biop->genome) {
 
8082
    case GENOME_apicoplast :
 
8083
    case GENOME_chloroplast :
 
8084
    case GENOME_chromoplast :
 
8085
    case GENOME_kinetoplast :
 
8086
    case GENOME_mitochondrion :
 
8087
    case GENOME_plastid :
 
8088
    case GENOME_cyanelle :
 
8089
    case GENOME_leucoplast :
 
8090
    case GENOME_proplastid :
 
8091
      if (mitocount > 1)
 
8092
        sprintf (orgnelle, "; %s genes for %s products",
 
8093
                 organelleByGenome [biop->genome],
 
8094
                 organelleByGenome [biop->genome]);
 
8095
      else
 
8096
        sprintf (orgnelle, "; %s gene for %s product",
 
8097
                 organelleByGenome [biop->genome],
 
8098
                 organelleByGenome [biop->genome]);
 
8099
      StringCat (str, orgnelle);
 
8100
      break;
 
8101
    default :
 
8102
      if (mitochloroflag > 0) {
 
8103
        if (mitochloroflag > 10) {
 
8104
          /* beyond list */
 
8105
        }
 
8106
        else if (mitochloroflag == 10)
 
8107
          StringCat (str, "; alternatively spliced");
 
8108
        else {
 
8109
          if (mitocount > 1)
 
8110
            sprintf (orgnelle, "; nuclear genes for %s products",
 
8111
                     organelleByPopup [mitochloroflag]);
 
8112
          else
 
8113
            sprintf (orgnelle, "; nuclear gene for %s product",
 
8114
                     organelleByPopup [mitochloroflag]);
 
8115
          StringCat (str, orgnelle);
 
8116
        }
 
8117
      }
 
8118
      break;
 
8119
    }
 
8120
  }
 
8121
  StringCat (str, ".");
 
8122
}
 
8123
 
 
8124
/*---------------------------------------------------------------------*/
 
8125
/*                                                                     */
 
8126
/* FinishAutoDefProc () -- Finish the automatic generation of a        */
 
8127
/*                         definition line that was started in         */
 
8128
/*                         AutoDefProc ().                             */
 
8129
/*                                                                     */
 
8130
/*---------------------------------------------------------------------*/
 
8131
 
 
8132
static void FinishAutoDefProc (Uint2        entityID,
 
8133
                               SeqEntryPtr  sep,
 
8134
                               ValNodePtr   head,
 
8135
                               BioseqPtr    target,
 
8136
                               SeqEntryPtr  nsep,
 
8137
                               MolInfoPtr   mip,
 
8138
                               ValNodePtr   strings,
 
8139
                               BioSourcePtr biop,
 
8140
                               Int2         mitochloroflag)
 
8141
 
 
8142
{
 
8143
  Int2          featNum;
4949
8144
  Boolean       ddbjstyle = FALSE;
4950
8145
  DefFeatsPtr   dfp;
4951
 
  CharPtr       exonnumber;
4952
8146
  Int2          mitocount;
4953
 
  DefFeatsPtr   nextdfp;
4954
8147
  CharPtr       ptr;
4955
 
  RnaRefPtr     rrp;
4956
8148
  SeqFeatPtr    sfp;
4957
 
  Char          str [380];
4958
 
  tRNAPtr       trna;
 
8149
  Char          str [DEFLINE_MAX_LEN];
4959
8150
  ValNodePtr    ttl;
4960
 
  Char          text [64];
4961
 
  Char          orgnelle [80];
 
8151
  Char          text [TEXT_MAX_LEN];
4962
8152
  ValNodePtr    vnp;
4963
8153
 
4964
 
  if (GetAppParam ("SEQUIN", "PREFERENCES", "DATABASE", NULL, str, sizeof (str))) {
4965
 
    if (StringICmp (str, "DDBJ") == 0) {
 
8154
  /* Check configuration parameters to */
 
8155
  /* see if we are using DDBJ style.   */  
 
8156
 
 
8157
  if (GetAppParam ("SEQUIN", "PREFERENCES", "DATABASE", NULL,
 
8158
                   str, DEFLINE_MAX_LEN)) {
 
8159
    if (StringICmp (str, "DDBJ") == 0)
4966
8160
      ddbjstyle = TRUE;
4967
 
    }
4968
8161
  }
 
8162
 
 
8163
  /* Loop through all the features, building a */
 
8164
  /* defline from the info gathered on them.   */
 
8165
 
4969
8166
  vnp = head;
4970
 
  count = 0;
 
8167
  featNum = 0;
4971
8168
  mitocount = 0;
4972
8169
  while (vnp != NULL) {
4973
8170
    str [0] = '\0';
4974
8171
    dfp = (DefFeatsPtr) vnp->data.ptrvalue;
 
8172
 
 
8173
    /* Create a string for the feature */
 
8174
 
4975
8175
    if (dfp != NULL) {
4976
8176
      sfp = dfp->sfp;
4977
8177
      if (sfp != NULL || dfp->numUnknown > 0) {
4978
 
        count++;
 
8178
        featNum++;
4979
8179
        mitocount++;
4980
 
        /* FindGeneAndProtForCDS (entityID, sfp, &(dfp->gene), &(dfp->prot)); */
4981
 
        /* StringCpy (str, "unknown"); */
4982
8180
        text [0] = '\0';
4983
 
        if (dfp->subtype == FEATDEF_CDS && dfp->prot != NULL) {
4984
 
          if (dfp->suppressprefix) {
4985
 
            str [0] = '\0';
4986
 
            if (dfp->sfp->partial) {
4987
 
              StringCat (str, "partial cds");
4988
 
            } else {
4989
 
              StringCat (str, "complete cds");
4990
 
            }
4991
 
            if (dfp->altSplices > 1) {
4992
 
              StringCat (str, ", alternatively spliced");
4993
 
            }
4994
 
          } else if (dfp->protname != NULL) {
4995
 
            if (StringICmp (dfp->protname, "unknown") == 0 && (! StringHasNoText (dfp->genename))) {
4996
 
              StringNCpy_0 (text, dfp->genename, sizeof (text));
4997
 
              /* StringCat (str, "("); */
4998
 
              StringCat (str, text);
4999
 
              /* StringCat (str, ")"); */
5000
 
            } else {
5001
 
              StringNCpy_0 (str, dfp->protname, sizeof (str) - 100);
5002
 
              if (dfp->genename != NULL) {
5003
 
                StringNCpy_0 (text, dfp->genename, sizeof (text));
5004
 
                if (! StringHasNoText (text)) {
5005
 
                  StringCat (str, " (");
5006
 
                  StringCat (str, text);
5007
 
                  StringCat (str, ")");
5008
 
                }
5009
 
              }
5010
 
            }
5011
 
            if (dfp->lastInGroup || dfp->lastInType) {
5012
 
              if (mip != NULL) {
5013
 
                ptr = StringISearch (str, "precursor");
5014
 
                if (ptr != NULL && StringICmp (ptr, "precursor") == 0) {
5015
 
                  StringCat (str, ",");
5016
 
                }
5017
 
                if (mip->biomol == MOLECULE_TYPE_MRNA) {
5018
 
                  StringCat (str, " mRNA");
5019
 
                } else if (mip->biomol == MOLECULE_TYPE_PRE_MRNA) {
5020
 
                  StringCat (str, " precursor RNA");
5021
 
                } else {
5022
 
                  StringCat (str, " gene");
5023
 
                }
5024
 
              }
5025
 
              if (count > 1) {
5026
 
                StringCat (str, "s");
5027
 
              }
5028
 
              if (count < 2 && /* dfp->altSplices < 2 && */ (! StringHasNoText (dfp->allelename))) {
5029
 
                StringNCpy_0 (text, dfp->allelename, sizeof (text));
5030
 
                StringCat (str, ", ");
5031
 
                StringCat (str, text);
5032
 
                StringCat (str, " allele");
5033
 
              }
5034
 
              if (dfp->sfp->partial) {
5035
 
                StringCat (str, ", partial cds");
5036
 
              } else {
5037
 
                StringCat (str, ", complete cds");
5038
 
              }
5039
 
              if (dfp->altSplices > 1) {
5040
 
                StringCat (str, ", alternatively spliced");
5041
 
              }
5042
 
            }
5043
 
          }
5044
 
        } else if (dfp->subtype == FEATDEF_CDS && dfp->pseudo) {
5045
 
          if (dfp->genename != NULL) {
5046
 
            StringNCpy_0 (str, dfp->genename, sizeof (str) - 50);
5047
 
          }
5048
 
          if (dfp->lastInGroup || dfp->lastInType) {
5049
 
            StringCat (str, " pseudogene");
5050
 
            if (count > 1) {
5051
 
              StringCat (str, "s");
5052
 
            }
5053
 
            if (count < 2 && (! StringHasNoText (dfp->allelename))) {
5054
 
              StringNCpy_0 (text, dfp->allelename, sizeof (text));
5055
 
              StringCat (str, ", ");
5056
 
              StringCat (str, text);
5057
 
              StringCat (str, " allele");
5058
 
            }
5059
 
            if (dfp->sfp->partial) {
5060
 
              StringCat (str, ", partial sequence");
5061
 
            } else {
5062
 
              StringCat (str, ", complete sequence");
5063
 
            }
5064
 
          }
5065
 
        } else if (dfp->subtype == FEATDEF_CDS && dfp->prot == NULL && dfp->genename != NULL) {
5066
 
          StringNCpy_0 (str, dfp->genename, sizeof (str) - 50);
5067
 
          if (dfp->lastInGroup || dfp->lastInType) {
5068
 
            if (mip != NULL) {
5069
 
              ptr = StringISearch (str, "precursor");
5070
 
              if (ptr != NULL && StringICmp (ptr, "precursor") == 0) {
5071
 
                StringCat (str, ",");
5072
 
              }
5073
 
              if (mip->biomol == MOLECULE_TYPE_MRNA) {
5074
 
                StringCat (str, " mRNA");
5075
 
              } else if (mip->biomol == MOLECULE_TYPE_PRE_MRNA) {
5076
 
                StringCat (str, " precursor RNA");
5077
 
              } else {
5078
 
                StringCat (str, " gene");
5079
 
              }
5080
 
            }
5081
 
            if (count > 1) {
5082
 
              StringCat (str, "s");
5083
 
            }
5084
 
            if (count < 2 && (! StringHasNoText (dfp->allelename))) {
5085
 
              StringNCpy_0 (text, dfp->allelename, sizeof (text));
5086
 
              StringCat (str, ", ");
5087
 
              StringCat (str, text);
5088
 
              StringCat (str, " allele");
5089
 
            }
5090
 
            if (dfp->sfp->partial) {
5091
 
              StringCat (str, ", partial cds");
5092
 
            } else {
5093
 
              StringCat (str, ", complete cds");
5094
 
            }
5095
 
          }
5096
 
        } else if (dfp->subtype == FEATDEF_GENE) {
5097
 
          if (dfp->genename != NULL) {
5098
 
            StringNCpy_0 (str, dfp->genename, sizeof (str) - 50);
5099
 
          }
5100
 
          if (dfp->lastInGroup || dfp->lastInType) {
5101
 
            if (mip != NULL) {
5102
 
              if (mip->biomol == MOLECULE_TYPE_MRNA) {
5103
 
                StringCat (str, " mRNA");
5104
 
              } else if (mip->biomol == MOLECULE_TYPE_PRE_MRNA) {
5105
 
                StringCat (str, " precursor RNA");
5106
 
              } else {
5107
 
                StringCat (str, " gene");
5108
 
              }
5109
 
            } else {
5110
 
              StringCat (str, " gene");
5111
 
            }
5112
 
            if (count > 1) {
5113
 
              StringCat (str, "s");
5114
 
            }
5115
 
            if (count < 2 && (! StringHasNoText (dfp->allelename))) {
5116
 
              StringNCpy_0 (text, dfp->allelename, sizeof (text));
5117
 
              StringCat (str, ", ");
5118
 
              StringCat (str, text);
5119
 
              StringCat (str, " allele");
5120
 
            }
5121
 
            if (dfp->sfp->partial) {
5122
 
              StringCat (str, ", partial sequence");
5123
 
            } else {
5124
 
              StringCat (str, ", complete sequence");
5125
 
            }
5126
 
          }
5127
 
        } else if (dfp->subtype == FEATDEF_rRNA || dfp->subtype == FEATDEF_otherRNA) {
5128
 
          rrp = (RnaRefPtr) dfp->sfp->data.value.ptrvalue;
5129
 
          if (rrp != NULL) {
5130
 
            if (rrp->ext.choice == 1) {
5131
 
              StringNCpy_0 (str, (CharPtr) rrp->ext.value.ptrvalue, sizeof (str) - 50);
5132
 
              if (dfp->subtype == FEATDEF_rRNA) {
5133
 
                ptr = StringISearch (str, " rRNA");
5134
 
                if (ptr != NULL) {
5135
 
                  *ptr = '\0';
5136
 
                }
5137
 
                ptr = StringISearch (str, " ribosomal RNA");
5138
 
                if (ptr != NULL) {
5139
 
                  *ptr = '\0';
5140
 
                }
5141
 
                if (! StringHasNoText (str)) {
5142
 
                  StringCat (str, " ribosomal RNA");
5143
 
                }
5144
 
              } else if (dfp->subtype == FEATDEF_otherRNA) {
5145
 
              }
5146
 
              if (dfp->genename != NULL) {
5147
 
                StringNCpy_0 (text, dfp->genename, sizeof (text));
5148
 
                if (! StringHasNoText (text)) {
5149
 
                  StringCat (str, " (");
5150
 
                  StringCat (str, text);
5151
 
                  StringCat (str, ")");
5152
 
                }
5153
 
              }
5154
 
              if (dfp->lastInString || dfp->lastInGroup || dfp->lastInType) {
5155
 
                if (dfp->subtype == FEATDEF_rRNA && mip->biomol == MOLECULE_TYPE_GENOMIC) {
5156
 
                  StringCat (str, " gene");
5157
 
                  if (count > 1) {
5158
 
                    StringCat (str, "s");
5159
 
                  }
5160
 
                }
5161
 
              }
5162
 
              if (dfp->lastInGroup || dfp->lastInType) {
5163
 
                if (dfp->sfp->partial) {
5164
 
                  StringCat (str, ", partial sequence");
5165
 
                } else {
5166
 
                  StringCat (str, ", complete sequence");
5167
 
                }
5168
 
              }
5169
 
            }
5170
 
          }
5171
 
        } else if (dfp->subtype == FEATDEF_tRNA) {
5172
 
          rrp = (RnaRefPtr) dfp->sfp->data.value.ptrvalue;
5173
 
          if (rrp != NULL) {
5174
 
            if (rrp->ext.choice == 2) {
5175
 
              trna = rrp->ext.value.ptrvalue;
5176
 
              if (trna != NULL) {
5177
 
                if (FeatDefLabel (dfp->sfp, str, sizeof (str) - 2, OM_LABEL_CONTENT) > 0) {
5178
 
                  if (dfp->genename != NULL) {
5179
 
                    StringNCpy_0 (text, dfp->genename, sizeof (text));
5180
 
                    if (! StringHasNoText (text)) {
5181
 
                      StringCat (str, " (");
5182
 
                      StringCat (str, text);
5183
 
                      StringCat (str, ")");
5184
 
                    }
5185
 
                  }
5186
 
                  if (dfp->lastInGroup || dfp->lastInType) {
5187
 
                    StringCat (str, " gene");
5188
 
                    if (count > 1) {
5189
 
                      StringCat (str, "s");
5190
 
                    }
5191
 
                    if (dfp->sfp->partial) {
5192
 
                      StringCat (str, ", partial sequence");
5193
 
                    } else {
5194
 
                      StringCat (str, ", complete sequence");
5195
 
                    }
5196
 
                  }
5197
 
                }
5198
 
              }
5199
 
            }
5200
 
          }
5201
 
        } else if (dfp->subtype == FEATDEF_LTR) {
5202
 
          if (! StringHasNoText (sfp->comment)) {
5203
 
            StringNCpy_0 (str, sfp->comment, sizeof (str));
5204
 
            ptr = StringISearch (str, " long terminal repeat");
5205
 
            if (ptr != NULL) {
5206
 
              *ptr = '\0';
5207
 
            }
5208
 
            ptr = StringISearch (str, " long terminal repeat");
5209
 
            if (ptr != NULL) {
5210
 
              *ptr = '\0';
5211
 
            }
5212
 
            if (! StringHasNoText (str)) {
5213
 
              StringCat (str, " long terminal repeat");
5214
 
            }
5215
 
          } else {
5216
 
            /* StringCpy (str, "uncharacterized"); */
5217
 
            StringCpy (str, "long terminal repeat");
5218
 
          }
5219
 
          if (dfp->lastInGroup || dfp->lastInType) {
5220
 
            if (dfp->sfp->partial) {
5221
 
              StringCat (str, ", partial sequence");
5222
 
            } else {
5223
 
              StringCat (str, ", complete sequence");
5224
 
            }
5225
 
          }
5226
 
        } else if (dfp->subtype == FEATDEF_exon && target != NULL) {
5227
 
          if (dfp->protname != NULL) {
5228
 
            str [0] = '\0';
5229
 
            if (! dfp->suppressprefix) {
5230
 
              StringNCpy_0 (str, dfp->protname, sizeof (str) - 100);
5231
 
              if (dfp->genename != NULL) {
5232
 
                StringNCpy_0 (text, dfp->genename, sizeof (text));
5233
 
                if (! StringHasNoText (text)) {
5234
 
                  StringCat (str, " (");
5235
 
                  StringCat (str, text);
5236
 
                  StringCat (str, ") gene,");
5237
 
                  if (/* count < 2 && */ /* dfp->altSplices < 2 && */ (! StringHasNoText (dfp->allelename))) {
5238
 
                    StringNCpy_0 (text, dfp->allelename, sizeof (text));
5239
 
                    StringCat (str, " ");
5240
 
                    StringCat (str, text);
5241
 
                    StringCat (str, " allele,");
5242
 
                  }
5243
 
                }
5244
 
              }
5245
 
            }
5246
 
            if ((! StringHasNoText (str)) || dfp->suppressprefix) {
5247
 
              exonnumber = GetExonNumber (sfp->qual);
5248
 
              if (! dfp->suppressprefix) {
5249
 
                if (exonnumber == NULL) {
5250
 
                  if (StringStr (sfp->comment, "exon") != NULL && (! NextIsExon (vnp))) {
5251
 
                  } else {
5252
 
                    StringCat (str, " exon");
5253
 
                    if (NextIsExon (vnp)) {
5254
 
                      StringCat (str, "s");
5255
 
                    }
5256
 
                  }
5257
 
                } else {
5258
 
                  StringCat (str, " exon");
5259
 
                  if (NextIsExon (vnp)) {
5260
 
                    StringCat (str, "s");
5261
 
                  }
5262
 
                }
5263
 
              }
5264
 
              if (exonnumber != NULL) {
5265
 
                if (! dfp->suppressprefix) {
5266
 
                  StringCat (str, " ");
5267
 
                }
5268
 
                StringCat (str, exonnumber);
5269
 
              } else {
5270
 
                if (! StringHasNoText (sfp->comment)) {
5271
 
                  if (! dfp->suppressprefix) {
5272
 
                    StringCat (str, " ");
5273
 
                  }
5274
 
                  StringCat (str, sfp->comment);
5275
 
                }
5276
 
              }
5277
 
            }
5278
 
          } else if (dfp->genename != NULL) {
5279
 
            str [0] = '\0';
5280
 
            if (! dfp->suppressprefix) {
5281
 
              StringNCpy_0 (str, dfp->genename, sizeof (str));
5282
 
              StringCat (str, " gene,");
5283
 
            }
5284
 
            if ((! StringHasNoText (str)) || dfp->suppressprefix) {
5285
 
              exonnumber = GetExonNumber (sfp->qual);
5286
 
              if (! dfp->suppressprefix) {
5287
 
                if (exonnumber == NULL) {
5288
 
                  if (StringStr (sfp->comment, "exon") != NULL && (! NextIsExon (vnp))) {
5289
 
                  } else {
5290
 
                    StringCat (str, " exon");
5291
 
                    if (NextIsExon (vnp)) {
5292
 
                      StringCat (str, "s");
5293
 
                    }
5294
 
                  }
5295
 
                } else {
5296
 
                  StringCat (str, " exon");
5297
 
                  if (NextIsExon (vnp)) {
5298
 
                    StringCat (str, "s");
5299
 
                  }
5300
 
                }
5301
 
              }
5302
 
              if (exonnumber != NULL) {
5303
 
                if (! dfp->suppressprefix) {
5304
 
                  StringCat (str, " ");
5305
 
                }
5306
 
                StringCat (str, exonnumber);
5307
 
              } else {
5308
 
                if (! StringHasNoText (sfp->comment)) {
5309
 
                  if (! dfp->suppressprefix) {
5310
 
                    StringCat (str, " ");
5311
 
                  }
5312
 
                  StringCat (str, sfp->comment);
5313
 
                }
5314
 
              }
5315
 
            }
5316
 
          } else {
5317
 
            StringCpy (str, "uncharacterized exon");
5318
 
          }
5319
 
          /*
5320
 
          if (dfp->lastInGroup || dfp->lastInType) {
5321
 
            if (dfp->sfp->partial) {
5322
 
              StringCat (str, ", partial sequence");
5323
 
            } else {
5324
 
              StringCat (str, ", complete sequence");
5325
 
            }
5326
 
          }
5327
 
          */
5328
 
        } else if (dfp->numUnknown > 0) {
5329
 
          if (mip != NULL && mip->biomol == MOLECULE_TYPE_MRNA) {
5330
 
            StringCat (str, "unknown mRNA");
5331
 
          } else if (mip->biomol == MOLECULE_TYPE_PRE_MRNA) {
5332
 
            StringCat (str, " unknown precursor RNA");
5333
 
          } else {
5334
 
            StringCat (str, "unknown gene");
5335
 
          }
5336
 
          if (dfp->numUnknown > 1) {
5337
 
            StringCat (str, "s");
5338
 
          }
5339
 
        }
 
8181
        if (dfp->subtype == FEATDEF_CDS && dfp->prot != NULL)
 
8182
          AutoDef_AddProtein (dfp, mip, str, featNum);
 
8183
        else if (dfp->subtype == FEATDEF_CDS && dfp->pseudo)
 
8184
          AutoDef_AddPseudoGene (dfp, str, featNum, text);
 
8185
        else if (dfp->subtype == FEATDEF_CDS &&
 
8186
                 dfp->prot == NULL && dfp->genename != NULL)
 
8187
          AutoDef_AddmRNA (dfp, str, featNum, text, mip);
 
8188
        else if (dfp->subtype == FEATDEF_GENE)
 
8189
          AutoDef_AddGene (dfp, str, featNum, text, mip);
 
8190
        else if (dfp->subtype == FEATDEF_rRNA ||
 
8191
                 dfp->subtype == FEATDEF_otherRNA)
 
8192
          AutoDef_AddRRNAandOtherRNA (dfp, str, featNum, text, mip);
 
8193
        else if (dfp->subtype == FEATDEF_tRNA)
 
8194
          AutoDef_AddtRNA (dfp, str, featNum, text);
 
8195
        else if (dfp->subtype == FEATDEF_snoRNA)
 
8196
          AutoDef_AddsnoRNA (dfp, str, featNum, text, mip);
 
8197
        else if (dfp->subtype == FEATDEF_snRNA)
 
8198
          AutoDef_AddsnRNA (dfp, str, featNum, text, mip);
 
8199
        else if (dfp->subtype == FEATDEF_LTR)
 
8200
          AutoDef_AddLTR (dfp, str, sfp);
 
8201
        else if (dfp->subtype == FEATDEF_exon)
 
8202
          AutoDef_AddExon (dfp, str, text, vnp, sfp, mip);
 
8203
        else if (dfp->numUnknown > 0)
 
8204
          AutoDef_AddUnknown (dfp, str, mip);
5340
8205
      }
5341
8206
    }
 
8207
 
 
8208
    /* Add a separator, or a terminator if */
 
8209
    /* it's the last feature.              */
 
8210
 
5342
8211
    vnp = vnp->next;
5343
8212
    if (! StringHasNoText (str)) {
5344
 
      if (vnp == NULL) {
5345
 
        if (biop != NULL) {
5346
 
          orgnelle [0] = '\0';
5347
 
          switch (biop->genome) {
5348
 
            case GENOME_chloroplast :
5349
 
            case GENOME_chromoplast :
5350
 
            case GENOME_kinetoplast :
5351
 
            case GENOME_mitochondrion :
5352
 
            case GENOME_plastid :
5353
 
            case GENOME_cyanelle :
5354
 
            case GENOME_apicoplast :
5355
 
            case GENOME_leucoplast :
5356
 
            case GENOME_proplastid :
5357
 
              if (mitocount > 1) {
5358
 
                sprintf (orgnelle, "; %s genes for %s products", organelleByGenome [biop->genome], organelleByGenome [biop->genome]);
5359
 
              } else {
5360
 
                sprintf (orgnelle, "; %s gene for %s product", organelleByGenome [biop->genome], organelleByGenome [biop->genome]);
5361
 
              }
5362
 
              StringCat (str, orgnelle);
5363
 
              break;
5364
 
            default :
5365
 
              if (mitochloroflag > 0) {
5366
 
                if (mitochloroflag > 10) {
5367
 
                  /* beyond list */
5368
 
                } else if (mitochloroflag == 10) {
5369
 
                  StringCat (str, "; alternatively spliced");
5370
 
                } else {
5371
 
                  if (mitocount > 1) {
5372
 
                    sprintf (orgnelle, "; nuclear genes for %s products", organelleByPopup [mitochloroflag]);
5373
 
                  } else {
5374
 
                    sprintf (orgnelle, "; nuclear gene for %s product", organelleByPopup [mitochloroflag]);
5375
 
                  }
5376
 
                  StringCat (str, orgnelle);
5377
 
                }
5378
 
              }
5379
 
              break;
5380
 
          }
5381
 
          /*
5382
 
          if (biop->genome == GENOME_mitochondrion) {
5383
 
            if (mitocount > 1) {
5384
 
              StringCat (str, "; mitochondrial genes for mitochondrial products");
5385
 
            } else {
5386
 
              StringCat (str, "; mitochondrial gene for mitochondrial product");
5387
 
            }
5388
 
          } else if (biop->genome == GENOME_chloroplast) {
5389
 
            if (mitocount > 1) {
5390
 
              StringCat (str, "; chloroplast genes for chloroplast products");
5391
 
            } else {
5392
 
              StringCat (str, "; chloroplast gene for chloroplast product");
5393
 
            }
5394
 
          } else if (mitochloroflag > 0) {
5395
 
            switch (mitochloroflag) {
5396
 
              case 1 :
5397
 
                if (mitocount > 1) {
5398
 
                  StringCat (str, "; nuclear genes for mitochondrial products");
5399
 
                } else {
5400
 
                  StringCat (str, "; nuclear gene for mitochondrial product");
5401
 
                }
5402
 
                break;
5403
 
              case 2 :
5404
 
                if (mitocount > 1) {
5405
 
                   StringCat (str, "; nuclear genes for chloroplast products");
5406
 
                 } else {
5407
 
                   StringCat (str, "; nuclear gene for chloroplast product");
5408
 
                 }
5409
 
                break;
5410
 
              case 3 :
5411
 
                if (mitocount > 1) {
5412
 
                  StringCat (str, "; mitochondrial genes for mitochondrial products");
5413
 
                } else {
5414
 
                  StringCat (str, "; mitochondrial gene for mitochondrial product");
5415
 
                }
5416
 
                break;
5417
 
              case 4 :
5418
 
                if (mitocount > 1) {
5419
 
                   StringCat (str, "; chloroplast genes for chloroplast products");
5420
 
                 } else {
5421
 
                   StringCat (str, "; chloroplast gene for chloroplast product");
5422
 
                 }
5423
 
                break;
5424
 
              default :
5425
 
                break;
5426
 
            }
5427
 
          }
5428
 
          */
5429
 
        }
5430
 
        StringCat (str, ".");
5431
 
      } else if (vnp->next == NULL) {
5432
 
        nextdfp = (DefFeatsPtr) vnp->data.ptrvalue;
5433
 
        if (dfp->lastInPenultimate) {
5434
 
          if ((dfp->subtype == FEATDEF_rRNA && nextdfp->subtype == FEATDEF_otherRNA &&
5435
 
               dfp->sfp->partial == nextdfp->sfp->partial) ||
5436
 
              (dfp->subtype == FEATDEF_otherRNA && nextdfp->subtype == FEATDEF_rRNA &&
5437
 
               dfp->sfp->partial == nextdfp->sfp->partial)) {
5438
 
            StringCat (str, ", and");
5439
 
          } else if (dfp->subtype == FEATDEF_exon && nextdfp->subtype == FEATDEF_exon /* &&
5440
 
               dfp->sfp->partial == nextdfp->sfp->partial */) {
5441
 
            StringCat (str, " and");
5442
 
          } else {
5443
 
            StringCat (str, "; and");
5444
 
          }
5445
 
        } else if (dfp->lastInType || dfp->lastInGroup) {
5446
 
          if (count > 1) {
5447
 
            StringCat (str, ", and");
5448
 
          } else {
5449
 
            StringCat (str, " and");
5450
 
          }
5451
 
        } else if (nextdfp->lastInType || nextdfp->lastInGroup) {
5452
 
          if (count > 1) {
5453
 
            StringCat (str, ", and");
5454
 
          } else {
5455
 
            StringCat (str, " and");
5456
 
          }
5457
 
        } else {
5458
 
          if (count > 1) {
5459
 
            StringCat (str, ", and");
5460
 
          } else {
5461
 
            StringCat (str, " and");
5462
 
          }
5463
 
        }
5464
 
      } else {
5465
 
        nextdfp = (DefFeatsPtr) vnp->data.ptrvalue;
5466
 
        if (dfp->lastInPenultimate) {
5467
 
          if ((dfp->subtype == FEATDEF_rRNA && nextdfp->subtype == FEATDEF_otherRNA &&
5468
 
               dfp->sfp->partial == nextdfp->sfp->partial) ||
5469
 
              (dfp->subtype == FEATDEF_otherRNA && nextdfp->subtype == FEATDEF_rRNA &&
5470
 
               dfp->sfp->partial == nextdfp->sfp->partial)) {
5471
 
            StringCat (str, ", and");
5472
 
          } else if (dfp->subtype == FEATDEF_exon && nextdfp->subtype == FEATDEF_exon /* &&
5473
 
               dfp->sfp->partial == nextdfp->sfp->partial */) {
5474
 
            StringCat (str, ",");
5475
 
          } else {
5476
 
            StringCat (str, "; and");
5477
 
          }
5478
 
        } else if (dfp->lastInType || dfp->lastInGroup) {
5479
 
          StringCat (str, ";");
5480
 
        } else if (nextdfp->lastInType || nextdfp->lastInGroup) {
5481
 
          if (count > 1) {
5482
 
            StringCat (str, ", and");
5483
 
          } else {
5484
 
            StringCat (str, " and");
5485
 
          }
5486
 
        } else {
5487
 
          StringCat (str, ",");
5488
 
        }
5489
 
      }
 
8213
      if (vnp == NULL)
 
8214
        AutoDef_AddEnding (str, biop, mitocount, mitochloroflag);
 
8215
      else if (vnp->next == NULL)
 
8216
        AutoDef_AddPenultSeparator (dfp, str, vnp, featNum);
 
8217
      else
 
8218
        AutoDef_AddSeparator (dfp, str, vnp, featNum);
 
8219
    }
 
8220
 
 
8221
    /* Add the feature's string to the */
 
8222
    /* valnode list of strings.        */
 
8223
 
 
8224
    if (! StringHasNoText (str))
5490
8225
      ValNodeCopyStr (&strings, 0, str);
5491
 
    }
5492
 
    if (dfp->lastInString || dfp->lastInGroup || dfp->lastInType) {
5493
 
      count = 0;
5494
 
    }
 
8226
 
 
8227
    /* Clear the counter if last in a group */
 
8228
 
 
8229
    if (dfp->lastInString || dfp->lastInGroup || dfp->lastInType)
 
8230
      featNum = 0;
5495
8231
  }
5496
8232
 
 
8233
  /* Merge all the strings into one */
 
8234
 
5497
8235
  ptr = MergeValNodeStrings (strings, FALSE);
 
8236
 
 
8237
  /* Add the new defline to the descriptor */
 
8238
 
5498
8239
  if (nsep != NULL) {
5499
8240
    ttl = SeqEntryGetSeqDescr (nsep, Seq_descr_title, NULL);
5500
 
    if (ttl == NULL) {
 
8241
    if (ttl == NULL)
5501
8242
      ttl = SeqEntryGetSeqDescr (sep, Seq_descr_title, NULL);
5502
 
    }
5503
 
    if (ttl == NULL) {
 
8243
    if (ttl == NULL)
5504
8244
      ttl = CreateNewDescriptor (nsep, Seq_descr_title);
5505
 
    }
5506
8245
    if (ttl != NULL) {
5507
8246
      MemFree (ttl->data.ptrvalue);
5508
8247
      ttl->data.ptrvalue = ptr;
5509
8248
      ptr = NULL;
5510
8249
    }
5511
8250
  }
 
8251
 
 
8252
  /* Clean up defore exiting */
 
8253
 
5512
8254
  MemFree (ptr);
5513
8255
  ValNodeFreeData (strings);
5514
8256
  ValNodeFreeData (head);
5642
8384
  }
5643
8385
}
5644
8386
 
5645
 
static void AutoDefProc (Uint2 entityID, SeqEntryPtr sep, Boolean addMods,
5646
 
                         Boolean labelMods, Int2 maxMods, Boolean leaveInParen,
5647
 
                         BioseqPtr target, BioseqPtr seg, ValNodePtr nonUniqueOrgs,
5648
 
                         Int2 mitochloroflag, Boolean suppressAltSplice, BioseqPtr parent)
5649
 
 
5650
 
{
5651
 
  Char            allele [256];
5652
 
  BioseqContextPtr  bcp;
5653
 
  BioSourcePtr    biop;
5654
 
  BioseqPtr       bsp;
5655
 
  BioseqSetPtr    bssp;
5656
 
  SeqFeatPtr      cds;
5657
 
  Boolean         change;
5658
 
  CdRegionPtr     crp;
5659
 
  DefFeatsData    df;
5660
 
  DefFeatsPtr     dfp;
5661
 
  DefFeatsPtr     dfpx;
5662
 
  SeqMgrFeatContext  fcontext;
5663
 
  GBQualPtr       gbq;
5664
 
  SeqFeatPtr      gene;
5665
 
  Int2            group;
5666
 
  GeneRefPtr      grp;
5667
 
  GatherScope     gs;
5668
 
  ValNodePtr      head;
5669
 
  SeqLocPtr       lastslp;
5670
 
  Int4            left;
5671
 
  size_t          lenallele;
5672
 
  size_t          lenlocus;
5673
 
  MolInfoPtr      mip;
5674
 
  DefFeatsPtr     nextdfp;
5675
 
  SeqLocPtr       nextslp;
5676
 
  ValNodePtr      nextvnp;
5677
 
  SeqEntryPtr     nsep;
5678
 
  Int2            numUnknown;
5679
 
  BioseqPtr       part;
5680
 
  DefFeatsPtr     penult;
5681
 
  ValNodePtr      PNTR prevvnp;
5682
 
  ProtRefPtr      prp;
5683
 
  CharPtr         ptr;
5684
 
  Int4            right;
5685
 
  ValNodePtr      sdp;
5686
 
  SeqFeatPtr      sfp;
5687
 
  SeqIdPtr        sip;
5688
 
  SeqLocPtr       slp;
5689
 
  Char            str [128];
5690
 
  ValNodePtr      ttl;
5691
 
  ValNodePtr      strings;
5692
 
  ValNode         vn;
5693
 
  ValNodePtr      vnp;
5694
 
  ValNodePtr      vnpx;
5695
 
  SeqFeatXrefPtr  xref;
5696
 
 
5697
 
  if (sep == NULL) return;
 
8387
/*---------------------------------------------------------------------*/
 
8388
/*                                                                     */
 
8389
/* AutoDef_SetGroupingFlags () -- Loop through all the features and    */
 
8390
/*                                set flags if they are the last in    */
 
8391
/*                                a group, string, or type.            */
 
8392
/*                                                                     */
 
8393
/*---------------------------------------------------------------------*/
 
8394
 
 
8395
static void AutoDef_SetGroupingFlags (ValNodePtr vnp)
 
8396
{
 
8397
  Boolean       change;
 
8398
  DefFeatsPtr   dfp;
 
8399
  Int2          group;
 
8400
  DefFeatsPtr   nextdfp;
 
8401
  DefFeatsPtr   penult;
 
8402
 
 
8403
  group = 0;
 
8404
  penult = NULL;
 
8405
 
 
8406
  /* Loop through all the features, comparing */
 
8407
  /* the current feature to the next one.     */
 
8408
 
 
8409
  while (vnp != NULL) {
 
8410
    dfp = (DefFeatsPtr) vnp->data.ptrvalue;
 
8411
    vnp->choice = (Uint1) group;
 
8412
    vnp = vnp->next;
 
8413
 
 
8414
    /* If there is a next feat, compare */
 
8415
    /* it with the current one.         */
 
8416
 
 
8417
    if (vnp != NULL) {
 
8418
      change = FALSE;
 
8419
      nextdfp = (DefFeatsPtr) vnp->data.ptrvalue;
 
8420
 
 
8421
      if ((dfp->subtype     == FEATDEF_rRNA &&
 
8422
           nextdfp->subtype == FEATDEF_otherRNA) ||
 
8423
          (dfp->subtype     == FEATDEF_otherRNA &&
 
8424
           nextdfp->subtype == FEATDEF_rRNA)) {
 
8425
        dfp->lastInString = TRUE;
 
8426
        if (dfp->sfp->partial != nextdfp->sfp->partial) {
 
8427
          dfp->lastInGroup = TRUE;
 
8428
        }
 
8429
        change = TRUE;
 
8430
      }
 
8431
 
 
8432
      else if (dfp->subtype != nextdfp->subtype) {
 
8433
        if (dfp->subtype     == FEATDEF_exon &&
 
8434
            nextdfp->subtype == FEATDEF_CDS &&
 
8435
            nextdfp->suppressprefix) {
 
8436
          /* no separator between exons and appropriate cds */
 
8437
        } else {
 
8438
          dfp->lastInType = TRUE;
 
8439
          change = TRUE;
 
8440
        }
 
8441
      }
 
8442
 
 
8443
      /* If partial state is different, mark it */
 
8444
      /* as a new group, except for exons.      */    
 
8445
 
 
8446
      else if (dfp->sfp->partial != nextdfp->sfp->partial) {
 
8447
        if (!(dfp->subtype     == FEATDEF_exon &&
 
8448
              nextdfp->subtype == FEATDEF_exon)) {
 
8449
          dfp->lastInGroup = TRUE;
 
8450
          change = TRUE;
 
8451
        }
 
8452
      }
 
8453
 
 
8454
      else if (dfp->pseudo != nextdfp->pseudo) {
 
8455
        dfp->lastInGroup = TRUE;
 
8456
        change = TRUE;
 
8457
      }
 
8458
      
 
8459
      else if ((dfp->allelename != NULL) || (nextdfp->allelename != NULL)) {
 
8460
        dfp->lastInGroup = TRUE;
 
8461
        dfp->isAlleleGroup = TRUE;
 
8462
        if (dfp->sfp->partial != nextdfp->sfp->partial) {
 
8463
          dfp->lastInString = TRUE;
 
8464
        }
 
8465
        change = TRUE;
 
8466
      }
 
8467
 
 
8468
      else if (dfp->altSplices > 1 || nextdfp->altSplices > 1) {
 
8469
        dfp->lastInGroup = TRUE;
 
8470
        change = TRUE;
 
8471
      }
 
8472
 
 
8473
      if (change) {
 
8474
        group++;
 
8475
        penult = dfp;
 
8476
      }
 
8477
    }
 
8478
 
 
8479
    /* Since the next feature is NULL, we're on the */
 
8480
    /* last feature so all the last flags are TRUE. */
 
8481
 
 
8482
    else {
 
8483
      dfp->lastInString = TRUE;
 
8484
      dfp->lastInGroup = TRUE;
 
8485
      dfp->lastInType = TRUE;
 
8486
      group++;
 
8487
    }
 
8488
  }
 
8489
 
 
8490
  if (penult != NULL) {
 
8491
    penult->lastInPenultimate = TRUE;
 
8492
  }
 
8493
 
 
8494
}
 
8495
 
 
8496
/*---------------------------------------------------------------------*/
 
8497
/*                                                                     */
 
8498
/* GetExonProtNameFromCDS () -- Gets a protein name for an Exon by     */
 
8499
/*                              checking for overlap with a CDS feat.  */
 
8500
/*                                                                     */
 
8501
/*    Returns : The protein name in the dfp->protname field.  NULL if  */
 
8502
/*              not found.                                             */
 
8503
/*                                                                     */
 
8504
/*---------------------------------------------------------------------*/
 
8505
 
 
8506
static void GetExonProtNameFromCDS (DefFeatsPtr dfp)
 
8507
{
 
8508
  SeqFeatPtr         cdsSfp;
 
8509
  DefFeatsData       df;
 
8510
  SeqMgrFeatContext  fcontext;
 
8511
  SeqFeatPtr         mrnaSfp;
 
8512
 
 
8513
  /* Use the mRNA feature to check for overlap because the */
 
8514
  /* CDS  doesn't completely overlap all the exons.        */
 
8515
 
 
8516
  mrnaSfp = SeqMgrGetOverlappingmRNA (dfp->sfp->location, &fcontext);
 
8517
  if (NULL == mrnaSfp)
 
8518
    return;
 
8519
 
 
8520
  /* If it overlaps the CDS also, then use that */
 
8521
 
 
8522
  cdsSfp = SeqMgrGetOverlappingFeature (dfp->sfp->location,
 
8523
                                        FEATDEF_CDS,
 
8524
                                        NULL,
 
8525
                                        0,
 
8526
                                        NULL,
 
8527
                                        SIMPLE_OVERLAP,
 
8528
                                        &fcontext);
 
8529
  if (cdsSfp != NULL) {
 
8530
    if (dfp->protname == NULL) {
 
8531
      dfp->protname = fcontext.label; /* points to stable str */
 
8532
    } else {
 
8533
      df.protname = fcontext.label;
 
8534
      CombineProteinNames (dfp, &df);
 
8535
    }
 
8536
  }
 
8537
 
 
8538
  return;
 
8539
 
 
8540
}
 
8541
 
 
8542
/*---------------------------------------------------------------------*/
 
8543
/*                                                                     */
 
8544
/* GetProtNameForExons () -- Get a protein for a given exon feature    */
 
8545
/*                           to use in the defline.                    */
 
8546
/*                                                                     */
 
8547
/*---------------------------------------------------------------------*/
 
8548
 
 
8549
static void GetProtNameForExons (ValNodePtr head,
 
8550
                                 Uint2      entityID,
 
8551
                                 BioseqPtr  parent)
 
8552
{
 
8553
  SeqFeatPtr         cdsSfp;
 
8554
  DefFeatsData       df;
 
8555
  DefFeatsPtr        dfp;
 
8556
  SeqMgrFeatContext  fcontext;
 
8557
  SeqFeatPtr         gene;
 
8558
  Int4               left;
 
8559
  Int4               right;
 
8560
  ValNodePtr         vnp;
 
8561
  Boolean            found_protein;
 
8562
      
 
8563
  /* Loop through all the features that we've gathered data for */
 
8564
  /* and add a protein name to any that are exon features.      */
 
8565
 
 
8566
  for (vnp = head; vnp != NULL; vnp = vnp->next) {
 
8567
    found_protein = FALSE;
 
8568
 
 
8569
    dfp = (DefFeatsPtr) vnp->data.ptrvalue;
 
8570
 
 
8571
    /* If not an exon then skip */
 
8572
 
 
8573
    if ((dfp == NULL) || (dfp->subtype != FEATDEF_exon))
 
8574
      continue;
 
8575
 
 
8576
    /* If the exon has a gene, then use */
 
8577
    /* that to get the protein name.    */
 
8578
 
 
8579
    if (dfp->gene != NULL) {
 
8580
      gene = SeqMgrGetDesiredFeature (entityID, NULL, 0, 0,
 
8581
                                      dfp->gene, &fcontext);
 
8582
      if (gene == dfp->gene && (! gene->pseudo)) {
 
8583
        left = fcontext.left;
 
8584
        right = fcontext.right;
 
8585
        cdsSfp = SeqMgrGetNextFeature (parent, NULL, SEQFEAT_CDREGION,
 
8586
                                       0, &fcontext);
 
8587
        while (cdsSfp != NULL) {
 
8588
          if (fcontext.left >= left && 
 
8589
              fcontext.right <= right &&
 
8590
              (! cdsSfp->pseudo)) {
 
8591
            if (dfp->protname == NULL) {
 
8592
              dfp->protname = fcontext.label; /* points to stable str */
 
8593
            } else {
 
8594
              df.protname = fcontext.label;
 
8595
              CombineProteinNames (dfp, &df);
 
8596
            }
 
8597
            found_protein = TRUE;
 
8598
          }
 
8599
          cdsSfp = SeqMgrGetNextFeature (parent, cdsSfp, SEQFEAT_CDREGION,
 
8600
                                         0, &fcontext);
 
8601
        }
 
8602
      }
 
8603
    }
 
8604
 
 
8605
    /* Otherwise, try to get a protein name */
 
8606
    /* from an overlapping CDS.             */
 
8607
 
 
8608
    if (!found_protein) {
 
8609
      GetExonProtNameFromCDS (dfp);
 
8610
    }
 
8611
  }
 
8612
}
 
8613
 
 
8614
static SeqFeatPtr FindGeneForFeature(SeqFeatPtr sfp, BioseqPtr geneBsp)
 
8615
{
 
8616
  SeqFeatPtr gene;
 
8617
  GeneRefPtr grp;
 
8618
  ValNodePtr syn;
 
8619
  SeqMgrFeatContext  geneContext;
 
8620
 
 
8621
  /* select the gene for this feature */
 
8622
  grp = SeqMgrGetGeneXref (sfp);
 
8623
  if (SeqMgrGeneIsSuppressed (grp))
 
8624
  {
 
8625
    /* if the gene is suppressed, then don't select a gene */
 
8626
    gene = NULL;
 
8627
  }
 
8628
  else if (sfp->data.choice == SEQFEAT_GENE)
 
8629
  {
 
8630
    /* If this feature is a gene, then the gene this feature should
 
8631
       be associated with is itself */
 
8632
    gene = sfp;
 
8633
  }
 
8634
  else if (grp != NULL)
 
8635
  {
 
8636
    gene = SeqMgrGetFeatureByLabel (geneBsp, grp->locus, SEQFEAT_GENE, 0, &geneContext);
 
8637
    if (gene == NULL)
 
8638
      gene = SeqMgrGetFeatureByLabel (geneBsp, grp->locus_tag, SEQFEAT_GENE, 0, &geneContext);
 
8639
    if (gene == NULL)
 
8640
      gene = SeqMgrGetFeatureByLabel (geneBsp, grp->desc, SEQFEAT_GENE, 0, &geneContext);
 
8641
    for (syn = grp->syn; gene == NULL && syn != NULL; syn = syn->next)
 
8642
    {
 
8643
      gene = SeqMgrGetFeatureByLabel (geneBsp, syn->data.ptrvalue, SEQFEAT_GENE, 0, &geneContext);
 
8644
    }
 
8645
    if (gene == NULL)
 
8646
      gene = SeqMgrGetOverlappingGene (sfp->location, NULL);
 
8647
  }
 
8648
  else
 
8649
  {
 
8650
    gene = SeqMgrGetOverlappingGene (sfp->location, NULL);
 
8651
  }
 
8652
  return gene;
 
8653
}
 
8654
 
 
8655
/*---------------------------------------------------------------------*/
 
8656
/*                                                                     */
 
8657
/* AutoDefProc () -- Create a defline from scratch.                    */
 
8658
/*                                                                     */
 
8659
/*---------------------------------------------------------------------*/
 
8660
 
 
8661
static void AutoDefProc (Uint2       entityID,
 
8662
                         SeqEntryPtr sep,
 
8663
                         Boolean     addMods,
 
8664
                         Boolean     labelMods,
 
8665
                         Int2        maxMods,
 
8666
                         Boolean     leaveInParen,
 
8667
                         BioseqPtr   target,
 
8668
                         BioseqPtr   seg,
 
8669
                         ValNodePtr  nonUniqueOrgs,
 
8670
                         Int2        mitochloroflag,
 
8671
                         Boolean     suppressAltSplice,
 
8672
                         Boolean     excludeSpOrgs,
 
8673
                         BioseqPtr   parent)
 
8674
 
 
8675
{
 
8676
  Char               allele [256];
 
8677
  BioseqContextPtr   bcp;
 
8678
  BioSourcePtr       biop;
 
8679
  BioseqPtr          bsp;
 
8680
  BioseqSetPtr       bssp;
 
8681
  CdRegionPtr        crp;
 
8682
  DefFeatsPtr        dfp;
 
8683
  DefFeatsPtr        dfpx;
 
8684
  GBQualPtr          gbq;
 
8685
  GeneRefPtr         grp;
 
8686
  GatherScope        gs;
 
8687
  ValNodePtr         head;
 
8688
  Boolean            is_transgenic;
 
8689
  SeqLocPtr          lastslp;
 
8690
  size_t             lenallele;
 
8691
  size_t             lenlocus;
 
8692
  MolInfoPtr         mip;
 
8693
  DefFeatsPtr        nextdfp;
 
8694
  SeqLocPtr          nextslp;
 
8695
  ValNodePtr         nextvnp;
 
8696
  SeqEntryPtr        nsep;
 
8697
  Int2               numUnknown;
 
8698
  BioseqPtr          part;
 
8699
  ValNodePtr    PNTR prevvnp;
 
8700
  ProtRefPtr         prp;
 
8701
  CharPtr            ptr;
 
8702
  ValNodePtr         sdp;
 
8703
  SeqFeatPtr         sfp;
 
8704
  SeqIdPtr           sip;
 
8705
  SeqLocPtr          slp;
 
8706
  SubSourcePtr       ssp;
 
8707
  ValNodePtr         syn;
 
8708
  Char               taxName [196];
 
8709
  ValNodePtr         ttl;
 
8710
  ValNodePtr         strings;
 
8711
  ValNode            vn;
 
8712
  ValNodePtr         vnp;
 
8713
  ValNodePtr         vnpx;
 
8714
  SeqFeatXrefPtr     xref;
 
8715
  SeqFeatPtr         dummy;
 
8716
 
 
8717
  /* Check parameters */
 
8718
 
 
8719
  if (sep == NULL)
 
8720
    return;
 
8721
 
5698
8722
  if (target == NULL && seg == NULL) {
 
8723
 
 
8724
    /* If we have a Bioseq Set then recurse */
 
8725
    /* until we get a Bioseq.               */
 
8726
 
5699
8727
    if (IS_Bioseq_set (sep)) {
5700
8728
      bssp = (BioseqSetPtr) sep->data.ptrvalue;
5701
 
      if (bssp == NULL) return;
 
8729
      if (bssp == NULL)
 
8730
        return;
5702
8731
      if (bssp->_class == 7 ||
5703
 
          (bssp->_class >= 13 && bssp->_class <= 16)) {
5704
 
        for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
5705
 
          AutoDefProc (entityID, sep, addMods, labelMods, maxMods, leaveInParen, NULL, NULL, nonUniqueOrgs, mitochloroflag, suppressAltSplice, NULL);
5706
 
        }
 
8732
          (IsPopPhyEtcSet (bssp->_class))) {
 
8733
        for (sep = bssp->seq_set; sep != NULL; sep = sep->next)
 
8734
          AutoDefProc (entityID, sep, addMods, labelMods, maxMods,
 
8735
                       leaveInParen, NULL, NULL, nonUniqueOrgs,
 
8736
                       mitochloroflag, suppressAltSplice, excludeSpOrgs,
 
8737
                       NULL);
5707
8738
        return;
5708
8739
      }
5709
8740
    }
5710
8741
 
 
8742
    /* If we have a segmented bioseq then recursively */
 
8743
    /* call this function on each segment.            */
 
8744
 
5711
8745
    nsep = FindNucSeqEntry (sep);
5712
8746
    if (nsep != NULL) {
5713
8747
      bsp = (BioseqPtr) nsep->data.ptrvalue;
5714
 
      if (bsp != NULL && bsp->repr == Seq_repr_seg && bsp->seq_ext != NULL && bsp->seq_ext_type == 1) {
 
8748
      if (bsp != NULL && bsp->repr == Seq_repr_seg &&
 
8749
          bsp->seq_ext != NULL && bsp->seq_ext_type == 1) {
5715
8750
        vn.choice = SEQLOC_MIX;
5716
8751
        vn.next = NULL;
5717
8752
        vn.data.ptrvalue = bsp->seq_ext;
5721
8756
          sip = SeqLocId (slp);
5722
8757
          if (sip != NULL) {
5723
8758
            part = BioseqFind (sip);
5724
 
            if (part != NULL) {
5725
 
              AutoDefProc (entityID, sep, addMods, labelMods, maxMods, leaveInParen, part, NULL, nonUniqueOrgs, mitochloroflag, suppressAltSplice, bsp);
5726
 
            }
 
8759
            if (part != NULL)
 
8760
              AutoDefProc (entityID, sep, addMods, labelMods, maxMods,
 
8761
                           leaveInParen, part, NULL, nonUniqueOrgs,
 
8762
                           mitochloroflag, suppressAltSplice, excludeSpOrgs,
 
8763
                           bsp);
5727
8764
          }
5728
8765
          slp = nextslp;
5729
8766
        }
5730
 
        AutoDefProc (entityID, sep, addMods, labelMods, maxMods, leaveInParen, NULL, bsp, nonUniqueOrgs, mitochloroflag, suppressAltSplice, bsp);
 
8767
        AutoDefProc (entityID, sep, addMods, labelMods, maxMods,
 
8768
                     leaveInParen, NULL, bsp, nonUniqueOrgs,
 
8769
                     mitochloroflag, suppressAltSplice, excludeSpOrgs, bsp);
5731
8770
        return;
5732
8771
      }
5733
8772
    }
5734
 
  } else if (target != NULL) {
 
8773
  }
 
8774
 
 
8775
  /* Otherwise, get the SeqEntry and its */
 
8776
  /* corresponding BioSource.            */
 
8777
 
 
8778
  else if (target != NULL)
5735
8779
    nsep = SeqMgrGetSeqEntryForData (target);
5736
 
  } else {
 
8780
  else
5737
8781
    nsep = SeqMgrGetSeqEntryForData (seg);
5738
 
  }
5739
8782
 
5740
8783
  biop = NULL;
5741
8784
  strings = NULL;
5742
 
  str [0] = '\0';
5743
 
 
5744
 
  SeqEntryToBioSource (sep, NULL, str, sizeof (str) - 1, &biop);
 
8785
  taxName [0] = '\0';
 
8786
 
 
8787
  SeqEntryToBioSource (sep, NULL, taxName, sizeof (taxName) - 1, &biop);
 
8788
 
 
8789
  /* Perform some cleanup of the taxonomic name */
 
8790
 
5745
8791
  if (! leaveInParen) {
5746
 
    ptr = StringStr (str, "(");
5747
 
    if (ptr != NULL) {
 
8792
    ptr = StringStr (taxName, "(");
 
8793
    if (ptr != NULL)
5748
8794
      *ptr = '\0';
 
8795
  }
 
8796
 
 
8797
  TrimSpacesAroundString (taxName);
 
8798
  if ((StringICmp (taxName, "Human immunodeficiency virus type 1") == 0) ||
 
8799
      (StringICmp (taxName, "Human immunodeficiency virus 1") == 0))
 
8800
    StringCpy (taxName, "HIV-1");
 
8801
  else if ((StringICmp (taxName,"Human immunodeficiency virus type 2") == 0) ||
 
8802
             (StringICmp (taxName, "Human immunodeficiency virus 2") == 0))
 
8803
    StringCpy (taxName, "HIV-2");
 
8804
 
 
8805
  taxName [0] = TO_UPPER (taxName [0]);
 
8806
 
 
8807
  is_transgenic = FALSE;
 
8808
  if (biop != NULL) {
 
8809
    for (ssp = biop->subtype; ssp != NULL; ssp = ssp->next) {
 
8810
      if (ssp->subtype == SUBSRC_transgenic)
 
8811
        is_transgenic = TRUE;
5749
8812
    }
5750
8813
  }
5751
 
  TrimSpacesAroundString (str);
5752
 
  if (StringICmp (str, "Human immunodeficiency virus type 1") == 0) {
5753
 
    StringCpy (str, "HIV-1");
5754
 
  } else if (StringICmp (str, "Human immunodeficiency virus type 2") == 0) {
5755
 
    StringCpy (str, "HIV-2");
5756
 
  }
5757
 
  str [0] = TO_UPPER (str [0]);
5758
 
  ValNodeCopyStr (&strings, 0, str);
 
8814
  if (is_transgenic)
 
8815
    StringCat (taxName, " transgenic");
 
8816
 
 
8817
  ValNodeCopyStr (&strings, 0, taxName);
 
8818
 
 
8819
  /**/
5759
8820
 
5760
8821
  mip = NULL;
5761
8822
  if (nsep != NULL) {
5771
8832
            mip->tech == MI_TECH_htgs_2 ||
5772
8833
            mip->tech == MI_TECH_est ||
5773
8834
            mip->tech == MI_TECH_sts ||
5774
 
            mip->tech == MI_TECH_survey) {
 
8835
            mip->tech == MI_TECH_survey ||
 
8836
            mip->tech == MI_TECH_wgs) {
5775
8837
          ttl = ValNodeExtract (&(bsp->descr), Seq_descr_title);
5776
 
          if (ttl != NULL) {
 
8838
          if (ttl != NULL)
5777
8839
            ttl = ValNodeFreeData (ttl);
5778
 
          }
5779
8840
          return;
5780
8841
        }
5781
8842
      }
5782
8843
    }
5783
8844
  }
5784
8845
 
5785
 
  /*
5786
 
  nsep = FindNucSeqEntry (sep);
5787
 
  if (nsep != NULL) {
5788
 
    sdp = SeqEntryGetSeqDescr (nsep, Seq_descr_molinfo, NULL);
5789
 
    if (sdp == NULL) {
5790
 
      sdp = SeqEntryGetSeqDescr (sep, Seq_descr_molinfo, NULL);
5791
 
    }
5792
 
    if (sdp != NULL) {
5793
 
      mip = (MolInfoPtr) sdp->data.ptrvalue;
5794
 
    }
5795
 
  }
5796
 
  */
 
8846
  /* Add Org Mods if necessary */
5797
8847
 
5798
8848
  if (nonUniqueOrgs != NULL) {
5799
 
    for (vnp = nonUniqueOrgs; vnp != NULL; vnp = vnp->next) {
5800
 
      if (StringICmp ((CharPtr) vnp->data.ptrvalue, str) == 0) {
5801
 
        if (vnp->choice == 1) {
5802
 
          addMods = FALSE; /* if only one organism in record, already unique defline */
5803
 
        }
5804
 
      }
5805
 
    }
 
8849
    for (vnp = nonUniqueOrgs; vnp != NULL; vnp = vnp->next)
 
8850
      if (StringICmp ((CharPtr) vnp->data.ptrvalue, taxName) == 0)
 
8851
        /* If only one organism in record, already unique defline */
 
8852
        if (vnp->choice == 1)
 
8853
          addMods = FALSE;
5806
8854
  }
 
8855
 
5807
8856
  if (addMods) {
5808
 
    AddOrgModsToDef (&strings, biop, labelMods);
 
8857
    AddOrgModsToDef (&strings, biop, labelMods, excludeSpOrgs);
5809
8858
    strings = SortValNode (strings, SortByVnpChoice);
5810
8859
    vnp = strings;
5811
8860
    while (vnp != NULL && maxMods > 0) {
5812
8861
      maxMods--;
5813
8862
      vnp = vnp->next;
5814
8863
    }
5815
 
    if (vnp != NULL) {
 
8864
    if (vnp != NULL)
5816
8865
      vnp->next = ValNodeFreeData (vnp->next);
5817
 
    }
5818
8866
  }
5819
8867
 
 
8868
  /* Gather info on all the Gene, CDS, tRNA, and rRNA features */
 
8869
 
5820
8870
  MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
5821
8871
  gs.seglevels = 1;
5822
8872
  gs.get_feats_location = TRUE;
5823
 
  MemSet ((Pointer) (gs.ignore), (int)(TRUE), (size_t) (OBJ_MAX * sizeof(Boolean)));
 
8873
  MemSet ((Pointer) (gs.ignore), (int)(TRUE),
 
8874
          (size_t) (OBJ_MAX * sizeof(Boolean)));
5824
8875
  gs.ignore[OBJ_BIOSEQ] = FALSE;
5825
8876
  gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
5826
8877
  gs.ignore[OBJ_SEQANNOT] = FALSE;
5835
8886
    gs.target = slp;
5836
8887
  }
5837
8888
  head = NULL;
5838
 
  GatherEntity (entityID, (Pointer) (&head), GetGeneCDStRNArRNAGatherFunc, &gs);
 
8889
  GatherEntity (entityID, (Pointer) (&head), GetGeneCDStRNArRNAGatherFunc,
 
8890
                &gs);
5839
8891
  gs.target = SeqLocFree (gs.target);
 
8892
 
5840
8893
  head = SortValNode (head, SortCDStRNArRNAByLocation);
5841
8894
 
5842
 
  if (head == NULL && mip != NULL && mip->tech == MI_TECH_survey) {
 
8895
  if (head == NULL && mip != NULL && mip->tech == MI_TECH_survey)
5843
8896
    ValNodeCopyStr (&strings, 0, ", genome survey sequence.");
5844
 
  }
 
8897
 
 
8898
  /* Loop through the features, gathering  */
 
8899
  /* additional info on them.              */
5845
8900
 
5846
8901
  numUnknown = 0;
5847
8902
  vnp = head;
5850
8905
    if (dfp != NULL) {
5851
8906
      sfp = dfp->sfp;
5852
8907
      if (sfp != NULL) {
5853
 
        FindGeneAndProtForCDS (entityID, sfp, &(dfp->gene), &(dfp->prot));
5854
 
        grp = SeqMgrGetGeneXref (sfp);
5855
 
        if (SeqMgrGeneIsSuppressed (grp)) {
5856
 
          dfp->gene = NULL;
5857
 
        }
 
8908
 
 
8909
        dfp->gene = FindGeneForFeature(sfp, target == NULL ? seg : target);
 
8910
 
 
8911
        /* use old method to get protein */
 
8912
        FindGeneAndProtForCDS (entityID, sfp, &dummy, &(dfp->prot));
 
8913
        
5858
8914
        dfp->pseudo = FALSE;
5859
8915
        dfp->genename = NULL;
5860
8916
        dfp->allelename = NULL;
5861
8917
        grp = NULL;
5862
8918
        if (dfp->gene != NULL) {
5863
8919
          grp = (GeneRefPtr) dfp->gene->data.value.ptrvalue;
5864
 
          if (grp != NULL && grp->pseudo) {
 
8920
          if (grp != NULL && grp->pseudo)
5865
8921
            dfp->pseudo = TRUE;
5866
 
          }
5867
8922
        }
5868
8923
        xref = sfp->xref;
5869
 
        while (xref != NULL && xref->data.choice != SEQFEAT_GENE) {
 
8924
        while (xref != NULL && xref->data.choice != SEQFEAT_GENE)
5870
8925
          xref = xref->next;
5871
 
        }
5872
 
        if (xref != NULL) {
 
8926
        if (xref != NULL)
5873
8927
          grp = (GeneRefPtr) xref->data.value.ptrvalue;
5874
 
        }
5875
8928
        if (grp != NULL) {
5876
8929
          dfp->genename = (CharPtr) grp->locus;
5877
 
          if ((! StringHasNoText (grp->locus)) && (! StringHasNoText (grp->allele))) {
 
8930
          if (StringHasNoText (dfp->genename)) {
 
8931
            dfp->genename = (CharPtr) grp->desc;
 
8932
          }
 
8933
          if (StringHasNoText (dfp->genename)) {
 
8934
            syn = grp->syn;
 
8935
            if (syn != NULL) {
 
8936
              dfp->genename = (CharPtr) syn->data.ptrvalue;
 
8937
            }
 
8938
          }
 
8939
          if (StringHasNoText (dfp->genename)) {
 
8940
            dfp->genename = (CharPtr) grp->locus_tag;
 
8941
          }
 
8942
          if ((! StringHasNoText (dfp->genename)) &&
 
8943
              (! StringHasNoText (grp->allele))) {
5878
8944
            lenallele = StringLen (grp->allele);
5879
 
            lenlocus = StringLen (grp->locus);
5880
 
            if (lenallele > lenlocus && StringNICmp (grp->locus, grp->allele, lenlocus) == 0) {
 
8945
            lenlocus = StringLen (dfp->genename);
 
8946
            if (lenallele > lenlocus &&
 
8947
                StringNICmp (dfp->genename, grp->allele, lenlocus) == 0)
5881
8948
              sprintf (allele, "%s", grp->allele);
5882
 
            } else if (StringNCmp (grp->allele, "-", 1) == 0) {
5883
 
              sprintf (allele, "%s%s", grp->locus, grp->allele);
5884
 
            } else {
5885
 
              sprintf (allele, "%s-%s", grp->locus, grp->allele);
5886
 
            }
 
8949
            else if (StringNCmp (grp->allele, "-", 1) == 0)
 
8950
              sprintf (allele, "%s%s", dfp->genename, grp->allele);
 
8951
            else
 
8952
              sprintf (allele, "%s-%s", dfp->genename, grp->allele);
5887
8953
            dfp->allelename = StringSave (allele);
5888
8954
          }
5889
 
          if (grp->pseudo) {
 
8955
          if (grp->pseudo)
5890
8956
            dfp->pseudo = TRUE;
5891
 
          }
5892
8957
        }
5893
8958
        if (dfp->subtype == FEATDEF_CDS) {
5894
8959
          if (target != NULL) {
5900
8965
            }
5901
8966
            if (lastslp != NULL && nsep != NULL) {
5902
8967
              bsp = (BioseqPtr) nsep->data.ptrvalue;
5903
 
              if (GetBioseqGivenSeqLoc (lastslp, entityID) != bsp) {
 
8968
              if (GetBioseqGivenSeqLoc (lastslp, entityID) != bsp)
5904
8969
                dfp->ignore = TRUE;
5905
 
              }
5906
8970
            }
5907
8971
          }
5908
8972
          crp = (CdRegionPtr) sfp->data.value.ptrvalue;
5909
 
          if (crp != NULL) {
5910
 
            if (crp->orf) {
 
8973
          if (crp != NULL)
 
8974
            if (crp->orf)
5911
8975
              dfp->ignore = TRUE;
5912
 
            }
5913
 
          }
 
8976
 
5914
8977
          gbq = sfp->qual;
5915
8978
          while (gbq != NULL) {
5916
 
            if (StringICmp (gbq->qual, "pseudo") == 0) {
 
8979
            if (StringICmp (gbq->qual, "pseudo") == 0)
5917
8980
              dfp->pseudo = TRUE;
5918
 
            }
5919
8981
            gbq = gbq->next;
5920
8982
          }
 
8983
 
5921
8984
          if (dfp->pseudo) {
5922
 
          } else if (dfp->prot == NULL) {
5923
 
            if (dfp->gene == NULL) {
 
8985
          }
 
8986
          else if (dfp->prot == NULL) {
 
8987
            if (dfp->gene == NULL)
5924
8988
              dfp->ignore = TRUE;
5925
 
            }
5926
 
          } else {
 
8989
          }
 
8990
          else {
5927
8991
            prp = (ProtRefPtr) dfp->prot->data.value.ptrvalue;
5928
8992
            if (prp != NULL) {
5929
 
              if (prp->name == NULL || StringHasNoText ((CharPtr) prp->name->data.ptrvalue)) {
5930
 
                if (prp->desc == NULL || StringHasNoText (prp->desc)) {
 
8993
              if (prp->name == NULL ||
 
8994
                  StringHasNoText ((CharPtr) prp->name->data.ptrvalue)) {
 
8995
                if (prp->desc == NULL || StringHasNoText (prp->desc))
5931
8996
                  dfp->ignore = TRUE;
5932
 
                } else {
 
8997
                else
5933
8998
                  dfp->protname = prp->desc;
5934
 
                }
5935
 
              } else {
 
8999
              }
 
9000
              else
5936
9001
                dfp->protname = (CharPtr) prp->name->data.ptrvalue;
5937
 
              }
5938
9002
              if (! dfp->ignore) {
5939
9003
                if (StringICmp (dfp->protname, "unknown") == 0) {
5940
9004
                  if (StringHasNoText (dfp->genename)) {
5945
9009
              }
5946
9010
            }
5947
9011
          }
5948
 
        } else if (dfp->subtype == FEATDEF_exon && target == NULL) {
5949
 
          dfp->ignore = TRUE;
5950
9012
        }
5951
9013
      }
5952
9014
    }
5961
9023
        if (sfp->data.choice == SEQFEAT_GENE) {
5962
9024
          for (vnpx = vnp->next; vnpx != NULL; vnpx = vnpx->next) {
5963
9025
            dfpx = (DefFeatsPtr) vnpx->data.ptrvalue;
5964
 
            if (dfpx != NULL) {
5965
 
              if (sfp == dfpx->gene) {
 
9026
            if (dfpx != NULL && dfpx != dfp)
 
9027
              if (sfp == dfpx->gene)
5966
9028
                dfp->ignore = TRUE;
5967
 
              }
5968
 
            }
5969
9029
          }
5970
9030
        }
5971
9031
      }
5981
9041
      *prevvnp = vnp->next;
5982
9042
      vnp->next = NULL;
5983
9043
      ValNodeFreeData (vnp);
5984
 
    } else {
 
9044
    }
 
9045
    else
5985
9046
      prevvnp = (ValNodePtr PNTR) &(vnp->next);
5986
 
    }
5987
9047
    vnp = nextvnp;
5988
9048
  }
5989
9049
 
5990
 
  if (! suppressAltSplice) {
 
9050
  if (! suppressAltSplice)
5991
9051
    MergeAltSpliceCDSs (head);
5992
 
  }
5993
9052
 
5994
 
  if (target != NULL) {
5995
 
    head = SortValNode (head, SortCDSAfterExons);
5996
 
  }
 
9053
  head = SortValNode (head, SortCDSAfterExons);
5997
9054
 
5998
9055
  if (numUnknown > 0) {
5999
9056
    dfp = (DefFeatsPtr) MemNew (sizeof (DefFeatsData));
6005
9062
    }
6006
9063
  }
6007
9064
 
6008
 
  if (target != NULL) {
6009
 
    for (vnp = head; vnp != NULL; vnp = vnp->next) {
6010
 
      dfp = (DefFeatsPtr) vnp->data.ptrvalue;
6011
 
      if (dfp != NULL && dfp->subtype == FEATDEF_exon && dfp->gene != NULL) {
6012
 
        gene = SeqMgrGetDesiredFeature (entityID, NULL, 0, 0, dfp->gene, &fcontext);
6013
 
        if (gene == dfp->gene && (! gene->pseudo)) {
6014
 
          left = fcontext.left;
6015
 
          right = fcontext.right;
6016
 
          cds = SeqMgrGetNextFeature (parent, NULL, SEQFEAT_CDREGION, 0, &fcontext);
6017
 
          while (cds != NULL) {
6018
 
            if (fcontext.left >= left && fcontext.right <= right && (! cds->pseudo)) {
6019
 
              if (dfp->protname == NULL) {
6020
 
                dfp->protname = fcontext.label; /* points to stable string */
6021
 
              } else {
6022
 
                df.protname = fcontext.label;
6023
 
                CombineProteinNames (dfp, &df);
6024
 
              }
6025
 
            }
6026
 
            cds = SeqMgrGetNextFeature (parent, cds, SEQFEAT_CDREGION, 0, &fcontext);
6027
 
          }
6028
 
        }
6029
 
      }
6030
 
    }
6031
 
    vnp = head;
6032
 
    while (vnp != NULL) {
6033
 
      dfp = (DefFeatsPtr) vnp->data.ptrvalue;
6034
 
      vnp = vnp->next;
6035
 
      if (dfp != NULL && dfp->subtype == FEATDEF_exon && vnp != NULL) {
6036
 
        nextdfp = (DefFeatsPtr) vnp->data.ptrvalue;
6037
 
        if (nextdfp != NULL && (nextdfp->subtype == FEATDEF_exon || nextdfp->subtype == FEATDEF_CDS)) {
6038
 
          if (StringCmp (dfp->genename, nextdfp->genename) == 0 &&
6039
 
              StringCmp (dfp->protname, nextdfp->protname) == 0) {
6040
 
            nextdfp->suppressprefix = TRUE;
6041
 
          }
6042
 
        }
6043
 
      }
6044
 
    }
6045
 
  }
6046
 
 
 
9065
  GetProtNameForExons (head, entityID, parent);
6047
9066
  vnp = head;
6048
 
  group = 0;
6049
 
  penult = NULL;
6050
9067
  while (vnp != NULL) {
6051
9068
    dfp = (DefFeatsPtr) vnp->data.ptrvalue;
6052
 
    vnp->choice = (Uint1) group;
6053
9069
    vnp = vnp->next;
6054
 
    if (vnp != NULL) {
6055
 
      change = FALSE;
 
9070
    if (dfp != NULL && dfp->subtype == FEATDEF_exon && vnp != NULL) {
6056
9071
      nextdfp = (DefFeatsPtr) vnp->data.ptrvalue;
6057
 
      if ((dfp->subtype == FEATDEF_rRNA && nextdfp->subtype == FEATDEF_otherRNA) ||
6058
 
          (dfp->subtype == FEATDEF_otherRNA && nextdfp->subtype == FEATDEF_rRNA)) {
6059
 
        dfp->lastInString = TRUE;
6060
 
        if (dfp->sfp->partial != nextdfp->sfp->partial) {
6061
 
          dfp->lastInGroup = TRUE;
6062
 
        }
6063
 
        change = TRUE;
6064
 
      } else if (dfp->subtype != nextdfp->subtype) {
6065
 
        if (dfp->subtype == FEATDEF_exon && nextdfp->subtype == FEATDEF_CDS && nextdfp->suppressprefix) {
6066
 
          /* no separator between exons and appropriate cds */
6067
 
        } else {
6068
 
          dfp->lastInType = TRUE;
6069
 
          change = TRUE;
6070
 
        }
6071
 
      } else if (dfp->sfp->partial != nextdfp->sfp->partial) {
6072
 
        dfp->lastInGroup = TRUE;
6073
 
        change = TRUE;
6074
 
      } else if (dfp->pseudo != nextdfp->pseudo) {
6075
 
        dfp->lastInGroup = TRUE;
6076
 
        change = TRUE;
6077
 
      } else if (dfp->allelename != NULL || nextdfp->allelename != NULL) {
6078
 
        dfp->lastInGroup = TRUE;
6079
 
        change = TRUE;
6080
 
      } else if (dfp->altSplices > 1 || nextdfp->altSplices > 1) {
6081
 
        dfp->lastInGroup = TRUE;
6082
 
        change = TRUE;
6083
 
      }
6084
 
      if (change) {
6085
 
        group++;
6086
 
        penult = dfp;
6087
 
      }
6088
 
    } else {
6089
 
      dfp->lastInString = TRUE;
6090
 
      dfp->lastInGroup = TRUE;
6091
 
      dfp->lastInType = TRUE;
6092
 
      group++;
 
9072
      if (nextdfp != NULL &&
 
9073
            (nextdfp->subtype == FEATDEF_exon ||
 
9074
             nextdfp->subtype == FEATDEF_CDS))
 
9075
      {
 
9076
        if ((StringCmp (dfp->genename, nextdfp->genename) == 0 &&
 
9077
            StringCmp (dfp->protname, nextdfp->protname) == 0)
 
9078
         || (StringCmp (dfp->genename, nextdfp->genename) == 0 &&
 
9079
            dfp->protname == NULL && nextdfp->protname == NULL)
 
9080
         || (dfp->genename == NULL && nextdfp->genename == NULL &&
 
9081
            StringCmp (dfp->protname, nextdfp->protname) == 0)
 
9082
         || (dfp->genename == NULL && nextdfp->genename == NULL &&
 
9083
            dfp->protname == NULL && nextdfp->protname == NULL))
 
9084
        {
 
9085
          nextdfp->suppressprefix = TRUE;
 
9086
        }
 
9087
      }
6093
9088
    }
6094
9089
  }
6095
 
  if (penult != NULL) {
6096
 
    penult->lastInPenultimate = TRUE;
6097
 
  }
6098
9090
 
6099
 
  FinishAutoDefProc (entityID, sep, head, target, nsep, mip, strings, biop, mitochloroflag);
 
9091
  AutoDef_SetGroupingFlags (head);
 
9092
  FinishAutoDefProc (entityID, sep, head, target, nsep, mip,
 
9093
                     strings, biop, mitochloroflag);
6100
9094
}
6101
9095
 
6102
9096
static CharPtr sourceModRankList [] = {
6108
9102
  "Environmental-sample", "Chromosome", "Segment", "Map", "Genotype", "Sex",
6109
9103
  "Plasmid-name", "Transposon-name", "Ins-seq-name", "Endogenous-virus-name",
6110
9104
  "Plastid-name", "Country", "Old Name", "Common", "Acronym", "Dosage",
6111
 
  "Natural-host", "Sub-species", "Specimen-voucher", "Isolation-source",
 
9105
  "Specific-host", "Sub-species", "Specimen-voucher", "Isolation-source",
6112
9106
  "Authority", "Forma", "Forma-specialis", "Ecotype", "Synonym", "Anamorph",
6113
9107
  "Teleomorph", "Breed",
6114
9108
  NULL
6132
9126
  ButtoN         onlyModifyTargeted;
6133
9127
  BioseqPtr      target;
6134
9128
  ButtoN         leaveInParentheses;
6135
 
  /*
6136
 
  GrouP          nucformitoorchloro;
6137
 
  */
 
9129
  ButtoN         excludeSpOrganisms;
6138
9130
  PopuP          nucformitoorchloro;
6139
9131
  Boolean        smartMods;
6140
9132
  ButtoN         suppressAltSplice;
6195
9187
    str = StringSave (orp->taxname);
6196
9188
    if (str == NULL) return TRUE;
6197
9189
    TrimSpacesAroundString (str);
6198
 
    if (StringICmp (str, "Human immunodeficiency virus type 1") == 0) {
 
9190
    if ((StringICmp (str, "Human immunodeficiency virus type 1") == 0) ||
 
9191
        (StringICmp (str, "Human immunodeficiency virus 1") == 0)) {
6199
9192
      StringCpy (str, "HIV-1");
6200
 
    } else if (StringICmp (str, "Human immunodeficiency virus type 2") == 0) {
 
9193
    } else if ((StringICmp (str, "Human immunodeficiency virus type 2") == 0) ||
 
9194
               (StringICmp (str, "Human immunodeficiency virus 2") == 0)) {
6201
9195
      StringCpy (str, "HIV-2");
6202
9196
    }
6203
9197
    str [0] = TO_UPPER (str [0]);
6206
9200
  return TRUE;
6207
9201
}
6208
9202
 
 
9203
static Boolean FindNonSpOrganisms(Uint2 entityID)
 
9204
{
 
9205
  GatherScope        gs;
 
9206
  ValNodePtr         Orgs;
 
9207
  ValNodePtr         vnp;
 
9208
 
 
9209
  Orgs = NULL;
 
9210
  MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
 
9211
  gs.seglevels = 1;
 
9212
  MemSet ((Pointer) (gs.ignore), (int)(TRUE), (size_t) (OBJ_MAX * sizeof(Boolean)));
 
9213
  gs.ignore[OBJ_BIOSEQ] = FALSE;
 
9214
  gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
 
9215
  gs.ignore[OBJ_SEQANNOT] = FALSE;
 
9216
  gs.ignore[OBJ_SEQFEAT] = FALSE;
 
9217
  gs.ignore[OBJ_SEQDESC] = FALSE;
 
9218
  GatherEntity (entityID, (Pointer) (&Orgs), GatherOrgnamesFunc, &gs);
 
9219
  vnp = Orgs;
 
9220
  while (vnp != NULL) {
 
9221
    if (vnp->data.ptrvalue == NULL) 
 
9222
    {
 
9223
      return TRUE;
 
9224
    }
 
9225
    if (StringStr ((CharPtr) vnp->data.ptrvalue, " sp.") == NULL)
 
9226
    {
 
9227
      return TRUE;
 
9228
    }
 
9229
    vnp = vnp->next;
 
9230
  }
 
9231
  return FALSE;
 
9232
}
 
9233
 
6209
9234
static void DefLineModFormAcceptProc (ButtoN b)
6210
9235
 
6211
9236
{
6212
9237
  EnumFieldAssocPtr  ap;
6213
9238
  Int2               count;
6214
9239
  DeflineFormPtr     dfp;
 
9240
  Boolean            excludeSpOrgs;
6215
9241
  GatherScope        gs;
6216
9242
  Boolean            labelMods;
6217
9243
  Boolean            leaveInParen;
6222
9248
  Boolean            suppressAltSplice;
6223
9249
  Int2               val;
6224
9250
  ValNodePtr         vnp;
 
9251
  MsgAnswer          ans;
6225
9252
 
6226
9253
  dfp = (DeflineFormPtr) GetObjectExtra (b);
6227
9254
  if (dfp == NULL) return;
 
9255
 
 
9256
  excludeSpOrgs = FALSE;
 
9257
  if (dfp->smartMods || 
 
9258
        (dfp->excludeSpOrganisms != NULL
 
9259
        && GetStatus (dfp->excludeSpOrganisms)))
 
9260
    excludeSpOrgs = TRUE; 
 
9261
 
 
9262
  if (excludeSpOrgs)
 
9263
  {
 
9264
    if (!FindNonSpOrganisms(dfp->input_entityID))
 
9265
    {
 
9266
      if (dfp->smartMods)
 
9267
      { 
 
9268
        excludeSpOrgs = FALSE;
 
9269
      }
 
9270
      else
 
9271
      {
 
9272
        ans = Message (MSG_YN, "There are only sp. organisms in the sequence(s), but you have opted to omit organism modifiers from sp. organisms - do you really want to omit all organism modifiers?");
 
9273
        if (ans == ANS_NO) return;
 
9274
      }
 
9275
    }
 
9276
  }
 
9277
  
6228
9278
  WatchCursor ();
6229
9279
  Hide (dfp->form);
6230
9280
  Update ();
6243
9293
        }
6244
9294
        for (ap = subsource_subtype_alist; ap->name != NULL; ap++) {
6245
9295
          if (StringICmp (ap->name, sourceModAlphaList [count].value) == 0 &&
6246
 
              ap->value > 0 && ap->value < 25) {
 
9296
              ap->value > 0 && ap->value < 29) {
6247
9297
            subsource_rank [ap->value] = 0;
6248
9298
          }
6249
9299
        }
6263
9313
  }
6264
9314
 
6265
9315
  leaveInParen = FALSE;
6266
 
  if (dfp->leaveInParentheses != NULL && GetStatus (dfp->leaveInParentheses)) {
 
9316
  if (dfp->leaveInParentheses != NULL && GetStatus (dfp->leaveInParentheses))
6267
9317
    leaveInParen = TRUE;
6268
 
  }
6269
9318
 
6270
9319
  nonUniqueOrgs = NULL;
6271
9320
  if (dfp->smartMods) {
6295
9344
 
6296
9345
  mitochloroflag = GetValue (dfp->nucformitoorchloro) - 1;
6297
9346
  suppressAltSplice = GetStatus (dfp->suppressAltSplice);
6298
 
  AutoDefProc (dfp->input_entityID, dfp->sep, TRUE, labelMods, maxMods, leaveInParen, NULL, NULL, nonUniqueOrgs, mitochloroflag, suppressAltSplice, NULL);
 
9347
  AutoDefProc (dfp->input_entityID, dfp->sep, TRUE, labelMods, maxMods,
 
9348
               leaveInParen, NULL, NULL, nonUniqueOrgs, mitochloroflag,
 
9349
               suppressAltSplice, excludeSpOrgs, NULL);
6299
9350
  ValNodeFreeData (nonUniqueOrgs);
6300
9351
  ClearProteinTitlesInNucProts (dfp->input_entityID, NULL);
6301
9352
  InstantiateProteinTitles (dfp->input_entityID, NULL);
6515
9566
    dfp->leaveInParentheses = CheckBox (w, "Leave in parenthetical organism info", NULL);
6516
9567
    SetStatus (dfp->leaveInParentheses, TRUE);
6517
9568
 
 
9569
    dfp->excludeSpOrganisms = CheckBox (w, "Do not apply modifier to 'sp.'"
 
9570
                                        " organisms", NULL);
 
9571
    SetStatus (dfp->excludeSpOrganisms, TRUE);
 
9572
 
6518
9573
    dfp->suppressAltSplice = CheckBox (w, "Suppress alternative splice phrase", NULL);
6519
9574
 
6520
9575
    dfp->onlyModifyTargeted = NULL;
6523
9578
    }
6524
9579
 
6525
9580
    c = HiddenGroup (w, 4, 0, NULL);
6526
 
    b = PushButton (c, "Accept", DefLineModFormAcceptProc);
 
9581
    b = DefaultButton (c, "Accept", DefLineModFormAcceptProc);
6527
9582
    SetObjectExtra (b, dfp, NULL);
6528
9583
    PushButton (c, "Cancel", StdCancelButtonProc);
6529
9584
 
6530
9585
    AlignObjects (ALIGN_CENTER, (HANDLE) dfp->addLabels, (HANDLE) dfp->customGrp,
6531
9586
                  (HANDLE) dfp->sourceListGrp, (HANDLE) q,
6532
9587
                  (HANDLE) dfp->leaveInParentheses,
 
9588
                  (HANDLE) dfp->excludeSpOrganisms,
6533
9589
                  (HANDLE) dfp->suppressAltSplice,
6534
9590
                  (HANDLE) dfp->nucformitoorchloro, (HANDLE) c,
6535
9591
                  (HANDLE) dfp->onlyModifyTargeted, NULL);
6584
9640
    }
6585
9641
    for (ap = subsource_subtype_alist; ap->name != NULL; ap++) {
6586
9642
      if (StringICmp (ap->name, sourceModAlphaList [count].value) == 0 &&
6587
 
          ap->value > 0 && ap->value < 25) {
 
9643
          ap->value > 0 && ap->value < 29) {
6588
9644
        subsource_rank [ap->value] = sourceModAlphaList[count].rank + 1;
6589
9645
      }
6590
9646
    }
6621
9677
 
6622
9678
  WatchCursor ();
6623
9679
  Update ();
6624
 
  AutoDefProc (bfp->input_entityID, sep, FALSE, FALSE, INT2_MAX, TRUE, NULL, NULL, NULL, 0, FALSE, NULL);
 
9680
  AutoDefProc (bfp->input_entityID, sep, FALSE, FALSE, INT2_MAX, TRUE, NULL, NULL, NULL, 0, FALSE, FALSE, NULL);
6625
9681
  ClearProteinTitlesInNucProts (bfp->input_entityID, NULL);
6626
9682
  InstantiateProteinTitles (bfp->input_entityID, NULL);
6627
9683
  ArrowCursor ();
6662
9718
  }
6663
9719
}
6664
9720
 
 
9721
static CharPtr molinfo_tech_list [] = {
 
9722
  "?", "standard", "EST", "STS", "survey", "genetic map", "physical map",
 
9723
  "derived", "concept-trans", "seq-pept", "both", "seq-pept-overlap",
 
9724
  "seq-pept-homol", "concept-trans-a", "htgs 1", "htgs 2", "htgs 3",
 
9725
  "fli cDNA", "htgs 0", "htc", "wgs", "barcode", NULL
 
9726
};
 
9727
 
6665
9728
static void MakeNucleotideTitlesInSequinStyle (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
6666
9729
 
6667
9730
{
6669
9732
  BioseqContextPtr   bcp;
6670
9733
  BioSourcePtr       biop;
6671
9734
  BioseqPtr          bsp;
 
9735
  MolInfoPtr         mip;
6672
9736
  OrgModPtr          mod;
6673
9737
  OrgNamePtr         onp;
6674
9738
  OrgRefPtr          orp;
6675
9739
  SeqDescrPtr        sdp;
6676
9740
  SubSourcePtr       ssp;
6677
9741
  CharPtr            str;
 
9742
  Uint1              tech = 0;
6678
9743
  Char               text [256];
6679
9744
  ValNodePtr         ttl;
6680
9745
  ValNodePtr         vnp;
6694
9759
    vnp = ValNodeExtract (&(bsp->descr), Seq_descr_title);
6695
9760
    vnp = ValNodeFreeData (vnp);
6696
9761
  }
 
9762
  bcp = BioseqContextNew (bsp);
 
9763
  sdp = BioseqContextGetSeqDescr (bcp, Seq_descr_molinfo, NULL, NULL);
 
9764
  if (sdp != NULL) {
 
9765
    mip = (MolInfoPtr) sdp->data.ptrvalue;
 
9766
    if (mip != NULL) {
 
9767
      switch (mip->tech) {
 
9768
        case MI_TECH_est :
 
9769
        case MI_TECH_sts :
 
9770
        case MI_TECH_survey :
 
9771
        case MI_TECH_htgs_1 :
 
9772
        case MI_TECH_htgs_2 :
 
9773
        case MI_TECH_htgs_3 :
 
9774
        case MI_TECH_fli_cdna :
 
9775
        case MI_TECH_htgs_0 :
 
9776
        case MI_TECH_htc :
 
9777
        case MI_TECH_wgs :
 
9778
          tech = mip->tech;
 
9779
          break;
 
9780
        default :
 
9781
          break;
 
9782
      }
 
9783
    }
 
9784
  }
 
9785
  BioseqContextFree (bcp);
6697
9786
  str = MemNew (2000);
6698
9787
 
6699
9788
  orp = biop->org;
6749
9838
    }
6750
9839
  }
6751
9840
 
 
9841
  if (tech > 0) {
 
9842
    StringCpy (text, "[tech=");
 
9843
    StringCat (text, molinfo_tech_list [tech]);
 
9844
    StringCat (text, "] ");
 
9845
    StringCat (str, text);
 
9846
  }
 
9847
 
6752
9848
  TrimSpacesAroundString (str);
6753
9849
  if (! StringHasNoText (str)) {
6754
9850
    ttl = CreateNewDescriptor (sep, Seq_descr_title);
6813
9909
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
6814
9910
    if (bssp == NULL) return;
6815
9911
    if (bssp->_class == 7 ||
6816
 
        (bssp->_class >= 13 && bssp->_class <= 16)) {
 
9912
        (IsPopPhyEtcSet (bssp->_class))) {
6817
9913
      for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
6818
9914
        MakeProteinTitlesInSequinStyle (entityID, sep);
6819
9915
      }
6855
9951
              StringCat (str, text);
6856
9952
              StringCat (str, "]");
6857
9953
            }
 
9954
            if (grp->syn != NULL) {
 
9955
              StringNCpy_0 (text, (CharPtr) grp->syn->data.ptrvalue, sizeof (text));
 
9956
              if (! StringHasNoText (text)) {
 
9957
                if (str [0] != '\0') {
 
9958
                  StringCat (str, " ");
 
9959
                }
 
9960
                StringCat (str, "[gene_syn=");
 
9961
                StringCat (str, text);
 
9962
                StringCat (str, "]");
 
9963
              }
 
9964
            }
6858
9965
          }
6859
9966
        }
6860
9967
        if (dfp->prot != NULL) {
6861
9968
          prp = (ProtRefPtr) dfp->prot->data.value.ptrvalue;
6862
 
          if (prp != NULL && prp->name != NULL) {
6863
 
            StringNCpy_0 (text, (CharPtr) prp->name->data.ptrvalue, sizeof (text));
 
9969
          if (prp != NULL) {
 
9970
            if (prp->name != NULL) {
 
9971
              StringNCpy_0 (text, (CharPtr) prp->name->data.ptrvalue, sizeof (text));
 
9972
              if (! StringHasNoText (text)) {
 
9973
                if (str [0] != '\0') {
 
9974
                  StringCat (str, " ");
 
9975
                }
 
9976
                StringCat (str, "[protein=");
 
9977
                StringCat (str, text);
 
9978
                StringCat (str, "]");
 
9979
              }
 
9980
            }
 
9981
            StringNCpy_0 (text, (CharPtr) prp->desc, sizeof (text));
6864
9982
            if (! StringHasNoText (text)) {
6865
 
              if (str [0] != '\0') {
6866
 
                StringCat (str, " ");
6867
 
              }
6868
 
              StringCat (str, "[protein=");
 
9983
              StringCat (str, "[prot_desc=");
6869
9984
              StringCat (str, text);
6870
9985
              StringCat (str, "]");
6871
9986
            }
6921
10036
 
6922
10037
  if (bsp == NULL) return TRUE;
6923
10038
  fp = (FILE *) context->userdata;
6924
 
  BioseqToGnbk (bsp, NULL, FTABLE_FMT, DUMP_MODE, NORMAL_STYLE, 0, fp);
 
10039
  BioseqToGnbk (bsp, NULL, FTABLE_FMT, DUMP_MODE, NORMAL_STYLE, 0, 0, 0, NULL, fp);
6925
10040
  return TRUE;
6926
10041
}
6927
10042
 
6962
10077
 
6963
10078
static void SqLitPrintGenome(SeqLitPtr slp, FILE *fp)
6964
10079
{
6965
 
        static Char             val[166];
6966
 
 
6967
10080
        if (slp->seq_data != NULL)         /* not a gap */
6968
10081
        {
6969
10082
                if (slp->length == 0)  /* unknown length */