~ubuntu-branches/ubuntu/edgy/ncbi-tools6/edgy

« back to all changes in this revision

Viewing changes to sequin/sequin4.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   6/28/96
31
31
*
32
 
* $Revision: 6.321 $
 
32
* $Revision: 6.351 $
33
33
*
34
34
* File Description: 
35
35
*
77
77
#include <valid.h>
78
78
#include <sqnutils.h>
79
79
#include <seqpanel.h>
 
80
#include <salpanel.h>
80
81
#include <findrepl.h>
81
82
 
82
83
static Int2 LIBCALLBACK CreateSegSet (Pointer data);
83
84
static Int2 LIBCALLBACK ConvertToDeltaSequence (Pointer data);
84
85
static Int2 LIBCALLBACK FeatToDeltaSeq (Pointer data);
 
86
static Int2 LIBCALLBACK CopyMasterSourceToSegments (Pointer data);
85
87
 
86
88
#define REGISTER_CREATESEGSET ObjMgrProcLoadEx (OMPROC_FILTER,"Create Segmented Set", "CreateSegSet", 0,0,0,0,NULL,CreateSegSet, PROC_PRIORITY_DEFAULT, "Indexer")
87
89
#define REGISTER_UPDATESEGSET ObjMgrProcLoadEx (OMPROC_FILTER,"Update Segmented Set","UpdateSegSet",0,0,0,0,NULL,UpdateSegSet,PROC_PRIORITY_DEFAULT, "Indexer")
110
112
 
111
113
#define REGISTER_UPDATE_SEQALIGN ObjMgrProcLoadEx (OMPROC_FILTER, "Update SeqAlign","UpdateSeqAlign",OBJ_SEQALIGN,0,OBJ_SEQALIGN,0,NULL,NewUpdateSeqAlign,PROC_PRIORITY_DEFAULT, "Alignment")
112
114
 
 
115
#define REGISTER_FIX_ALIGNMENT_OVER_GAPS ObjMgrProcLoadEx (OMPROC_FILTER, "Fix Alignment Over Gaps", "FixAlignmentOverGaps", 0,0,0,0,NULL,FixAlignmentOverGaps,PROC_PRIORITY_DEFAULT, "Alignment")
 
116
 
 
117
#define REGISTER_FIX_ALIGNMENT_GAP_GAPS ObjMgrProcLoadEx (OMPROC_FILTER, "Fix Alignment Gaps Containing Known Gaps", "FixKnownGapAlignmentGaps", 0,0,0,0,NULL,ConsolidateGapGaps, PROC_PRIORITY_DEFAULT, "Alignment")
 
118
 
113
119
#define REGISTER_DELETE_BY_TEXT ObjMgrProcLoadEx (OMPROC_FILTER, "Delete By Text","DeleteByText",0,0,0,0,NULL,CreateDeleteByTextWindow,PROC_PRIORITY_DEFAULT, "Indexer")
114
120
 
115
121
#define REGISTER_SEGREGATE_BY_TEXT ObjMgrProcLoadEx (OMPROC_FILTER, "Segregate By Text","SegregateByText",0,0,0,0,NULL,CreateSegregateByTextWindow,PROC_PRIORITY_DEFAULT, "Indexer")
120
126
 
121
127
#define REGISTER_SEGREGATE_BY_MOLECULE_TYPE ObjMgrProcLoadEx (OMPROC_FILTER, "Segregate By Molecule Type","SegregateByMoleculeType",0,0,0,0,NULL,CreateSegregateByMoleculeTypeWindow,PROC_PRIORITY_DEFAULT, "Indexer")
122
128
 
 
129
#define REGISTER_REORDER_BY_ID ObjMgrProcLoadEx (OMPROC_FILTER, "Reorder by ID","ReorderByID",0,0,0,0,NULL,ReorderSetByAccession,PROC_PRIORITY_DEFAULT, "Indexer")
 
130
 
123
131
#define REGISTER_CONVERTSEQALIGN ObjMgrProcLoadEx (OMPROC_FILTER,"Convert SeqAlign","ConvertSeqAlign",0,0,0,0,NULL,ConvertToTrueMultipleAlignment,PROC_PRIORITY_DEFAULT, "Alignment")
124
132
 
125
133
#define REGISTER_CONVERTTOSEGSETALIGN ObjMgrProcLoadEx (OMPROC_FILTER,"Convert to SegSetAlign","ConvertSegSetAlign",0,0,0,0,NULL,ConvertToSegSetAlignment,PROC_PRIORITY_DEFAULT, "Alignment")
126
134
 
127
135
#define REGISTER_MAKESEQALIGN ObjMgrProcLoadEx (OMPROC_FILTER,"Make SeqAlign","CreateSeqAlign",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntry,PROC_PRIORITY_DEFAULT, "Alignment")
128
136
 
 
137
#define REGISTER_MAKESEQALIGNNEWBLAST ObjMgrProcLoadEx (OMPROC_FILTER,"Make SeqAlign, New BLAST","CreateSeqAlignNewBLAST",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryUseNewBlast,PROC_PRIORITY_DEFAULT, "Alignment")
 
138
 
129
139
#define REGISTER_MAKESEQALIGNMASTER ObjMgrProcLoadEx (OMPROC_FILTER,"Make SeqAlign Choose Master","CreateSeqAlignChooseMaster",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryChooseMaster,PROC_PRIORITY_DEFAULT, "Alignment")
130
140
 
 
141
#define REGISTER_MAKESEQALIGNMASTERNEWBLAST ObjMgrProcLoadEx (OMPROC_FILTER,"Make SeqAlign Choose Master, New BLAST","CreateSeqAlignChooseMasterNewBLAST",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryChooseMasterUseNewBlast,PROC_PRIORITY_DEFAULT, "Alignment")
 
142
 
131
143
#define REGISTER_MAKESEQALIGNP ObjMgrProcLoadEx (OMPROC_FILTER,"Make Protein SeqAlign","CreateSeqAlignProt",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryProt,PROC_PRIORITY_DEFAULT, "Alignment")
132
144
 
 
145
#define REGISTER_MAKESEQALIGNPNEWBLAST ObjMgrProcLoadEx (OMPROC_FILTER,"Make Protein SeqAlign, New BLAST","CreateSeqAlignProtNewBLAST",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryProtUseNewBlast,PROC_PRIORITY_DEFAULT, "Alignment")
 
146
 
133
147
#define REGISTER_NORMSEQALIGN ObjMgrProcLoadEx (OMPROC_FILTER,"Validate SeqAlign","ValidateSeqAlign",0,0,0,0,NULL,ValidateSeqAlignFromData,PROC_PRIORITY_DEFAULT, "Alignment")
134
148
 
135
149
#define REGISTER_NOMORESEGGAP ObjMgrProcLoadEx (OMPROC_FILTER,"Get Rid of Seg Gap","GetRidOfSegGap",0,0,0,0,NULL,NoMoreSegGap,PROC_PRIORITY_DEFAULT, "Alignment")
183
197
 
184
198
#define REGISTER_DESCRIPTOR_PROPAGATE ObjMgrProcLoadEx (OMPROC_FILTER, "Descriptor Propagate", "DescriptorPropagate", 0, 0, 0, 0, NULL, DescriptorPropagate, PROC_PRIORITY_DEFAULT, "Indexer")
185
199
 
 
200
#define REGISTER_COPY_MASTER_SOURCE_TO_SEGMENTS ObjMgrProcLoadEx (OMPROC_FILTER, "Copy Master Source To Segments", "CopyMasterSourceToSegments", 0, 0, 0, 0, NULL, CopyMasterSourceToSegments, PROC_PRIORITY_DEFAULT, "Indexer")
 
201
 
186
202
#define REGISTER_CLEAR_SEQENTRYSCOPE ObjMgrProcLoadEx (OMPROC_FILTER, "Clear SeqEntry Scope", "ClearSeqEntryScope", 0, 0, 0, 0, NULL, DoClearSeqEntryScope, PROC_PRIORITY_DEFAULT, "Indexer")
187
203
 
188
204
#define REGISTER_SEQUIN_PROT_TITLES ObjMgrProcLoadEx (OMPROC_FILTER,"Sequin Style Protein Titles","SequinStyleProteinTitles",0,0,0,0,NULL,MakeSequinProteinTitles,PROC_PRIORITY_DEFAULT, "Misc")
212
228
#define REGISTER_REFGENEUSER_DESC_EDIT ObjMgrProcLoad(OMPROC_EDIT,"Edit RefGene UserTrack Desc","RefGene Tracking",OBJ_SEQDESC,Seq_descr_user,OBJ_SEQDESC,Seq_descr_user,NULL,RefGeneUserGenFunc,PROC_PRIORITY_DEFAULT)
213
229
extern Int2 LIBCALLBACK RefGeneUserGenFunc (Pointer data);
214
230
 
 
231
#define REGISTER_GENOMEPROJSDBUSER_DESC_EDIT ObjMgrProcLoad(OMPROC_EDIT,"Edit GenomeProjectsDB User Desc","GenomeProjectsDB",OBJ_SEQDESC,Seq_descr_user,OBJ_SEQDESC,Seq_descr_user,NULL,GenomeProjectsDBUserGenFunc,PROC_PRIORITY_DEFAULT)
 
232
extern Int2 LIBCALLBACK GenomeProjectsDBUserGenFunc (Pointer data);
 
233
 
215
234
#define REGISTER_TPAASSEMBLYUSER_DESC_EDIT ObjMgrProcLoad(OMPROC_EDIT,"Edit Assembly User Desc","TPA Assembly",OBJ_SEQDESC,Seq_descr_user,OBJ_SEQDESC,Seq_descr_user,NULL,AssemblyUserGenFunc,PROC_PRIORITY_DEFAULT)
216
235
 
217
236
#define REGISTER_CONVERT_TO_DELTA ObjMgrProcLoadEx (OMPROC_FILTER, "Convert to Delta Sequence", "ConvertToDelta", 0,0,0,0,NULL, ConvertToDeltaSequence, PROC_PRIORITY_DEFAULT, "Indexer")
359
378
  }
360
379
}
361
380
 
362
 
typedef struct descriptorextraction
363
 
{
364
 
  Int2 descriptor_choice;
365
 
  SeqDescrPtr sdp_list;
366
 
} DescriptorExtractionData, PNTR DescriptorExtractionPtr;
367
 
 
368
 
static void ExtractSegSetDescriptorsBioseqSetCallback (BioseqSetPtr bssp, Pointer userdata)
369
 
{
370
 
  DescriptorExtractionPtr dep;
371
 
  ValNodePtr              extracted_list;
372
 
  
373
 
  dep = (DescriptorExtractionPtr) userdata;
374
 
  if (bssp == NULL || dep == NULL || bssp->descr == NULL)
375
 
  {
376
 
    return;
377
 
  }
378
 
  
379
 
  extracted_list = ValNodeExtractList (&(bssp->descr), dep->descriptor_choice);
380
 
  ValNodeLink (&dep->sdp_list, extracted_list);
381
 
}
382
 
 
383
 
static void ExtractSegSetDescriptorsBioseqCallback (BioseqPtr bsp, Pointer userdata)
384
 
{
385
 
  DescriptorExtractionPtr dep;
386
 
  ValNodePtr              extracted_list;
387
 
  
388
 
  dep = (DescriptorExtractionPtr) userdata;
389
 
  if (bsp == NULL || dep == NULL || bsp->descr == NULL)
390
 
  {
391
 
    return;
392
 
  }
393
 
  
394
 
  extracted_list = ValNodeExtractList (&(bsp->descr), dep->descriptor_choice);
395
 
  ValNodeLink (&dep->sdp_list, extracted_list);
396
 
}
 
381
 
 
382
static Boolean DoDescriptorsMatch (SeqDescrPtr sdp1, SeqDescrPtr sdp2)
 
383
{
 
384
  if (sdp1 == NULL || sdp2 == NULL || sdp1->choice != sdp2->choice)
 
385
  {
 
386
    return FALSE;
 
387
  }
 
388
  
 
389
  /* compare publications */
 
390
  if (sdp1->choice == Seq_descr_pub
 
391
      && PubdescContentMatch (sdp1->data.ptrvalue, sdp2->data.ptrvalue))
 
392
  {
 
393
    return TRUE;
 
394
  }
 
395
  /* compare sources */
 
396
  else if (sdp1->choice == Seq_descr_source
 
397
      && BioSourceMatch (sdp1->data.ptrvalue, sdp2->data.ptrvalue))
 
398
  {
 
399
    return TRUE;
 
400
  }
 
401
  /* compare update dates */
 
402
  else if (sdp1->choice == Seq_descr_update_date
 
403
      && DateMatch (sdp1->data.ptrvalue, sdp2->data.ptrvalue, TRUE))
 
404
  {
 
405
    return TRUE;
 
406
  }
 
407
  else
 
408
  {
 
409
    return FALSE;
 
410
  }
 
411
}
 
412
 
 
413
static Boolean FindIdenticalDescriptorInEachBioseqInList (SeqDescrPtr sdp, SeqEntryPtr sep)
 
414
{
 
415
  SeqDescrPtr check_sdp;
 
416
  Boolean     found_match = FALSE;
 
417
  BioseqPtr   bsp;
 
418
  
 
419
  if (sdp == NULL)
 
420
  {
 
421
    return FALSE;
 
422
  }
 
423
  if (sep == NULL)
 
424
  {
 
425
    return TRUE;
 
426
  }
 
427
  
 
428
  if (!IS_Bioseq(sep) || sep->data.ptrvalue == NULL)
 
429
  {
 
430
    return FALSE;
 
431
  }
 
432
  
 
433
  bsp = (BioseqPtr) sep->data.ptrvalue;
 
434
  check_sdp = bsp->descr;
 
435
  while (check_sdp != NULL && !found_match)
 
436
  {
 
437
    found_match = DoDescriptorsMatch (check_sdp, sdp);
 
438
    check_sdp = check_sdp->next;
 
439
  }
 
440
  
 
441
  if (found_match)
 
442
  {
 
443
    found_match = FindIdenticalDescriptorInEachBioseqInList (sdp, sep->next);
 
444
  }
 
445
 
 
446
  return found_match;
 
447
}
 
448
 
 
449
 
 
450
static void RemoveIdenticalDescriptorInEachBioseqInList (SeqDescrPtr sdp, SeqEntryPtr sep)
 
451
{
 
452
  SeqDescrPtr check_sdp, prev = NULL;
 
453
  BioseqPtr   bsp;
 
454
  
 
455
  if (sdp == NULL || sep == NULL || !IS_Bioseq(sep) || sep->data.ptrvalue == NULL)
 
456
  {
 
457
    return;
 
458
  }
 
459
  
 
460
  bsp = (BioseqPtr) sep->data.ptrvalue;
 
461
  check_sdp = bsp->descr;
 
462
  while (check_sdp != NULL)
 
463
  {
 
464
    if (DoDescriptorsMatch (check_sdp, sdp))
 
465
    {
 
466
      if (prev == NULL)
 
467
      {
 
468
        bsp->descr = check_sdp->next;
 
469
      }
 
470
      else
 
471
      {
 
472
        prev->next = check_sdp->next;
 
473
      }
 
474
      check_sdp->next = NULL;
 
475
      check_sdp = SeqDescrFree (check_sdp);
 
476
    }
 
477
    else
 
478
    {
 
479
      prev = check_sdp;
 
480
      check_sdp = check_sdp->next;
 
481
    }
 
482
  }
 
483
 
 
484
  RemoveIdenticalDescriptorInEachBioseqInList (sdp, sep->next);
 
485
}
 
486
 
397
487
 
398
488
static void 
399
 
MoveSegSetDescriptorsUp
 
489
MoveUpIdenticalSegSetDescriptors 
400
490
(BioseqPtr    segseq, 
401
491
 BioseqSetPtr parts, 
402
492
 BioseqSetPtr segset,
403
493
 Int2         descriptor_choice)
404
 
 
405
494
{
406
495
  SeqEntryPtr  sep;
407
 
  DescriptorExtractionData ded;
 
496
  BioseqPtr    bsp;
408
497
  BioseqSetPtr bssp;
409
 
  BioseqPtr    bsp;
410
 
 
411
 
  if (segseq == NULL || parts == NULL || parts->seq_set == NULL || segset == NULL) return;
 
498
  SeqDescrPtr  sdp, sdp_next, prev = NULL;
 
499
  SeqDescrPtr  moved_list = NULL;
 
500
  
 
501
  if (segseq == NULL || parts == NULL || parts->seq_set == NULL || segset == NULL
 
502
      || ! IS_Bioseq (parts->seq_set) || parts->seq_set->data.ptrvalue == NULL)
 
503
  {
 
504
    return;
 
505
  }
 
506
  
412
507
  sep = GetBestTopParentForData (segseq->idx.entityID, segseq);
413
508
  if (sep == NULL)
414
509
  {
415
510
    sep = SeqMgrGetSeqEntryForData (segset);
416
511
  }
417
512
  
418
 
  if (sep == NULL || sep->data.ptrvalue == NULL) return;
419
 
  
420
 
  ded.descriptor_choice = descriptor_choice;
421
 
  ded.sdp_list = NULL;
422
 
  
423
 
  VisitSetsInSep (sep, &ded, ExtractSegSetDescriptorsBioseqSetCallback);
424
 
  VisitBioseqsInSep (sep, &ded, ExtractSegSetDescriptorsBioseqCallback);
 
513
  bsp = (BioseqPtr) parts->seq_set->data.ptrvalue;
 
514
  
 
515
  sdp = bsp->descr;
 
516
  while (sdp != NULL)
 
517
  {
 
518
    sdp_next = sdp->next;
 
519
    if (sdp->choice == descriptor_choice 
 
520
        && FindIdenticalDescriptorInEachBioseqInList (sdp, parts->seq_set->next))
 
521
    {
 
522
      RemoveIdenticalDescriptorInEachBioseqInList (sdp, parts->seq_set->next);
 
523
      if (prev == NULL)
 
524
      {
 
525
        bsp->descr = sdp->next;
 
526
      }
 
527
      else
 
528
      {
 
529
        prev->next = sdp->next;
 
530
      }
 
531
      sdp->next = NULL;
 
532
      ValNodeLink (&moved_list, sdp);
 
533
    }
 
534
    else
 
535
    {
 
536
      prev = sdp;
 
537
    }
 
538
    sdp = sdp_next;
 
539
  }
425
540
  
426
541
  if (IS_Bioseq_set (sep))
427
542
  {
428
543
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
429
 
    ValNodeLink (&(bssp->descr), ded.sdp_list);
 
544
    ValNodeLink (&(bssp->descr), moved_list);
430
545
  }
431
546
  else if (IS_Bioseq (sep))
432
547
  {
433
548
    bsp = (BioseqPtr) sep->data.ptrvalue;
434
 
    ValNodeLink (&(bsp->descr), ded.sdp_list);
 
549
    ValNodeLink (&(bsp->descr), moved_list);
435
550
  }
436
551
}
437
552
 
 
553
 
438
554
static void DoUpdateSegSet (BioseqPtr segseq, BioseqSetPtr parts, Boolean ask, Boolean force_intersperse)
439
555
 
440
556
{
618
734
    if (uss.segseq != NULL && uss.parts != NULL && uss.segset != NULL) {
619
735
      DoUpdateSegSet (uss.segseq, uss.parts, ask, FALSE);
620
736
      MoveSegSetMolInfo (uss.segseq, uss.parts, uss.segset);
621
 
      MoveSegSetDescriptorsUp (uss.segseq, uss.parts, uss.segset, Seq_descr_pub);
622
 
      MoveSegSetDescriptorsUp (uss.segseq, uss.parts, uss.segset, Seq_descr_update_date);
623
 
      MoveSegSetDescriptorsUp (uss.segseq, uss.parts, uss.segset, Seq_descr_source);      
 
737
      
 
738
      MoveUpIdenticalSegSetDescriptors (uss.segseq, uss.parts, uss.segset, Seq_descr_pub);
 
739
      MoveUpIdenticalSegSetDescriptors (uss.segseq, uss.parts, uss.segset, Seq_descr_update_date);
 
740
      MoveUpIdenticalSegSetDescriptors (uss.segseq, uss.parts, uss.segset, Seq_descr_source);      
624
741
    }
625
742
    return count;
626
743
  }
631
748
  if (uss.segseq != NULL && uss.parts != NULL && uss.segset != NULL) {
632
749
    DoUpdateSegSet (uss.segseq, uss.parts, ask, FALSE);
633
750
    MoveSegSetMolInfo (uss.segseq, uss.parts, uss.segset);
634
 
    MoveSegSetDescriptorsUp (uss.segseq, uss.parts, uss.segset, Seq_descr_pub);
635
 
    MoveSegSetDescriptorsUp (uss.segseq, uss.parts, uss.segset, Seq_descr_update_date);
636
 
    MoveSegSetDescriptorsUp (uss.segseq, uss.parts, uss.segset, Seq_descr_source);    
 
751
    
 
752
    MoveUpIdenticalSegSetDescriptors (uss.segseq, uss.parts, uss.segset, Seq_descr_pub);
 
753
    MoveUpIdenticalSegSetDescriptors (uss.segseq, uss.parts, uss.segset, Seq_descr_update_date);
 
754
    MoveUpIdenticalSegSetDescriptors (uss.segseq, uss.parts, uss.segset, Seq_descr_source);    
637
755
    return 1;
638
756
  }
639
757
  return 0;
715
833
  }
716
834
  DoUpdateSegSet (seg, parts, FALSE, intersperse_nulls);
717
835
  MoveSegSetMolInfo (seg, parts, seg_bssp);  
718
 
  MoveSegSetDescriptorsUp (seg, parts, seg_bssp, Seq_descr_pub);
719
 
  MoveSegSetDescriptorsUp (seg, parts, seg_bssp, Seq_descr_update_date);
720
 
  MoveSegSetDescriptorsUp (seg, parts, seg_bssp, Seq_descr_source);  
 
836
  MoveUpIdenticalSegSetDescriptors (seg, parts, seg_bssp, Seq_descr_pub);
 
837
  MoveUpIdenticalSegSetDescriptors (seg, parts, seg_bssp, Seq_descr_update_date);
 
838
  MoveUpIdenticalSegSetDescriptors (seg, parts, seg_bssp, Seq_descr_source);  
721
839
}
722
840
 
723
841
static void ConvertOneSetToSegSet (SeqEntryPtr sep, Boolean intersperse_nulls)
1026
1144
extern void DoFixupLocus (SeqEntryPtr sep);
1027
1145
extern void DoFixupSegSet (SeqEntryPtr sep);
1028
1146
 
1029
 
typedef struct donecancel
1030
 
{
1031
 
  Boolean done;
1032
 
  Boolean cancelled;
1033
 
} DoneCancelData, PNTR DoneCancelPtr;
1034
 
 
1035
 
static void DoneButton (ButtoN b)
1036
 
{
1037
 
  DoneCancelPtr dcp;
1038
 
  
1039
 
  dcp = (DoneCancelPtr) GetObjectExtra (b);
1040
 
  if (dcp != NULL)
1041
 
  {
1042
 
    dcp->cancelled = FALSE;
1043
 
    dcp->done = TRUE;
1044
 
  }
1045
 
}
1046
 
 
1047
 
static void CancelButton (ButtoN b)
1048
 
{
1049
 
  DoneCancelPtr dcp;
1050
 
  
1051
 
  dcp = (DoneCancelPtr) GetObjectExtra (b);
1052
 
  if (dcp != NULL)
1053
 
  {
1054
 
    dcp->cancelled = TRUE;
1055
 
    dcp->done = TRUE;
1056
 
  }
1057
 
}
1058
 
 
1059
1147
static Int2 LIBCALLBACK NewUpdateSegSet (Pointer data)
1060
1148
 
1061
1149
{
1062
 
  OMProcControlPtr   ompcp;
1063
 
  SeqEntryPtr        sep;
1064
 
  ErrSev             sev;
1065
 
  DoneCancelData     dcd;
1066
 
  WindoW             w;
1067
 
  GrouP              h, g, c;
1068
 
  ButtoN             intersperse_nulls_btn;
1069
 
  ButtoN             fix_locus_btn;
1070
 
  ButtoN             tax_fix_cleanup_btn;
1071
 
  ButtoN             b;
 
1150
  OMProcControlPtr       ompcp;
 
1151
  SeqEntryPtr            sep;
 
1152
  ErrSev                 sev;
 
1153
  ModalAcceptCancelData  acd;
 
1154
  WindoW                 w;
 
1155
  GrouP                  h, g, c;
 
1156
  ButtoN                 intersperse_nulls_btn;
 
1157
  ButtoN                 fix_locus_btn;
 
1158
  ButtoN                 tax_fix_cleanup_btn;
 
1159
  ButtoN                 b;
1072
1160
 
1073
1161
  ompcp = (OMProcControlPtr) data;
1074
1162
  if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
1098
1186
  tax_fix_cleanup_btn = CheckBox (g, "Do Tax_Fix/Cleanup", NULL);
1099
1187
  SetStatus (tax_fix_cleanup_btn, TRUE);
1100
1188
 
1101
 
  dcd.done = FALSE;
1102
 
  dcd.cancelled = FALSE;
 
1189
  acd.accepted = FALSE;
 
1190
  acd.cancelled = FALSE;
1103
1191
  c = HiddenGroup (h, 4, 0, NULL);
1104
 
  b = DefaultButton (c, "Accept", DoneButton);
1105
 
  SetObjectExtra (b, &dcd, NULL);
1106
 
  b = PushButton (c, "Cancel", CancelButton);
1107
 
  SetObjectExtra (b, &dcd, NULL);
 
1192
  b = DefaultButton (c, "Accept", ModalAcceptButton);
 
1193
  SetObjectExtra (b, &acd, NULL);
 
1194
  b = PushButton (c, "Cancel", ModalCancelButton);
 
1195
  SetObjectExtra (b, &acd, NULL);
1108
1196
 
1109
1197
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
1110
1198
  RealizeWindow (w);
1111
1199
  Show (w);
1112
1200
  Update ();
1113
1201
  
1114
 
  while (!dcd.done)
 
1202
  while (!acd.accepted && !acd.cancelled)
1115
1203
  {
1116
1204
    ProcessExternalEvent ();
1117
1205
    Update ();
1118
1206
  }
1119
1207
  ProcessAnEvent ();
1120
1208
  Hide (w);
1121
 
  if (dcd.cancelled)
 
1209
  if (acd.cancelled)
1122
1210
  {
1123
1211
    Remove (w);
1124
1212
        return OM_MSG_RET_DONE;
2661
2749
 
2662
2750
{
2663
2751
  OMProcControlPtr  ompcp;
2664
 
  SeqAlignPtr       salp, sap, next;
 
2752
  SeqAlignPtr       sap;
2665
2753
  SeqAnnotPtr       sanp;
2666
2754
 
2667
2755
  ompcp = (OMProcControlPtr) data;
2687
2775
        sap = (SeqAlignPtr)(sanp->data);
2688
2776
  }
2689
2777
  if (sap == NULL) return OM_MSG_RET_ERROR;
2690
 
  salp = sap;
2691
 
  while (salp != NULL)
2692
 
  {
2693
 
     if (salp->saip != NULL)
2694
 
     {
2695
 
        SeqAlignIndexFree(salp->saip);
2696
 
        salp->saip = NULL;
2697
 
     }
2698
 
     salp = salp->next;
2699
 
  }
2700
 
  AlnMgr2IndexSeqAlign (sap);
2701
 
 
2702
 
  salp = AlnMgr2GetSubAlign (sap, 0, -1, 0, FALSE);
2703
 
  if (salp == NULL) return OM_MSG_RET_ERROR;
2704
 
 
2705
 
  if (sap->idx.prevlink != NULL) {
2706
 
    *(sap->idx.prevlink) = (Pointer) salp;
2707
 
  }
2708
 
 
2709
 
  while (sap != NULL) {
2710
 
    next = sap->next;
2711
 
    sap->next = NULL;
2712
 
    SeqAlignFree (sap);
2713
 
    sap = next;
2714
 
  }
2715
 
 
 
2778
  
 
2779
  ConvertPairwiseToMultipleAlignment (sap);
 
2780
  
2716
2781
  ObjMgrSetDirtyFlag (ompcp->input_entityID, TRUE);
2717
2782
  ObjMgrSendMsg (OM_MSG_UPDATE, ompcp->input_entityID, 0, 0);
2718
2783
 
2719
2784
  return OM_MSG_RET_DONE;
2720
2785
}
2721
2786
 
2722
 
static SeqAnnotPtr GetSeqAnnotForAlignment (SeqAlignPtr sap)
2723
 
{
2724
 
  SeqAnnotPtr  sanp = NULL;
2725
 
  BioseqPtr    bsp;
2726
 
  BioseqSetPtr bssp;
2727
 
  Boolean      found = FALSE;
2728
 
  
2729
 
  if (sap == NULL)
2730
 
  {
2731
 
    return NULL;
2732
 
  }
2733
 
  
2734
 
  if (sap->idx.parenttype == OBJ_BIOSEQ)
2735
 
  {
2736
 
    bsp = (BioseqPtr) sap->idx.parentptr;
2737
 
    if (bsp != NULL)
2738
 
    {
2739
 
      sanp = bsp->annot;
2740
 
    }
2741
 
  }
2742
 
  else if (sap->idx.parenttype == OBJ_BIOSEQSET)
2743
 
  {
2744
 
    bssp = (BioseqSetPtr) sap->idx.parentptr;
2745
 
    if (bssp != NULL)
2746
 
    {
2747
 
      sanp = bssp->annot;
2748
 
    }
2749
 
  }
2750
 
  while (sanp != NULL && !found)
2751
 
  {
2752
 
    if (sanp->type == 2 && sanp->data == sap)
2753
 
    {
2754
 
      found = TRUE;
2755
 
    }
2756
 
    else
2757
 
    {
2758
 
      sanp = sanp->next;
2759
 
    }
2760
 
  }
2761
 
  return sanp;
2762
 
}
2763
 
 
2764
2787
static Int2 LIBCALLBACK ConvertToSegSetAlignment (Pointer data)
2765
2788
 
2766
2789
{
3512
3535
  return TRUE;
3513
3536
}
3514
3537
 
 
3538
 
 
3539
/* This function creates one SeqAnnot for each alignment in a chain of
 
3540
 * alignments, breaking the chain for each alignment.
 
3541
 * This is used to create the separate alignment annotations for a 
 
3542
 * discontiguous set of alignments, especially one created for a set
 
3543
 * that contains delta sequences.
 
3544
 */
 
3545
static void 
 
3546
CreateSeqAnnotsForDiscontiguousAlignments 
 
3547
(SeqAlignPtr  salp_mult,
 
3548
 Uint2        entityID,
 
3549
 BioseqSetPtr set_for_alignment)
 
3550
{
 
3551
  SeqAlignPtr       salp, salp_next;
 
3552
  SeqAnnotPtr       sap;
 
3553
  SeqEntryPtr       sep;
 
3554
  SeqAnnotPtr PNTR  sapp = NULL;
 
3555
  BioseqSetPtr      bssp;
 
3556
  BioseqPtr         bsp;
 
3557
  SeqAnnotPtr       curr;
 
3558
  
 
3559
  if (salp_mult == NULL)
 
3560
  {
 
3561
    return;
 
3562
  }
 
3563
  for (salp = salp_mult; salp != NULL; salp = salp_next)
 
3564
  {
 
3565
    salp_next = salp->next;
 
3566
    salp->next = NULL;
 
3567
    sap = SeqAnnotForSeqAlign(salp);
 
3568
    
 
3569
    if (sap != NULL) {
 
3570
      if (set_for_alignment == NULL)
 
3571
      {
 
3572
        sep = GetTopSeqEntryForEntityID (entityID);
 
3573
        if (sep != NULL && sep->data.ptrvalue != NULL) {
 
3574
          sapp = NULL;
 
3575
          if (IS_Bioseq (sep)) {
 
3576
            bsp = (BioseqPtr) sep->data.ptrvalue;
 
3577
            sapp = &(bsp->annot);
 
3578
          } else if (IS_Bioseq_set (sep)) {
 
3579
            bssp = (BioseqSetPtr) sep->data.ptrvalue;
 
3580
            sapp = &(bssp->annot);
 
3581
          }
 
3582
        }
 
3583
      }
 
3584
      else
 
3585
      {
 
3586
        sapp = &(set_for_alignment->annot);
 
3587
      }
 
3588
 
 
3589
      if (sapp != NULL) {
 
3590
        if (*sapp != NULL) {
 
3591
          curr = *sapp;
 
3592
          while (curr->next != NULL) {
 
3593
            curr = curr->next;
 
3594
          }
 
3595
          curr->next = sap;
 
3596
        } else {
 
3597
          *sapp = sap;
 
3598
        }
 
3599
      }
 
3600
    }
 
3601
  }
 
3602
}
 
3603
 
 
3604
 
3515
3605
static Int2 LIBCALLBACK NewUpdateSeqAlign (Pointer data)
3516
3606
 
3517
3607
{
3520
3610
  OMProcControlPtr  ompcp;
3521
3611
  SeqAlignPtr       salp=NULL,
3522
3612
                    salpnew;
3523
 
  SeqAnnotPtr       sap=NULL,
3524
 
                    sapcopy;
3525
3613
  SeqEntryPtr       sep=NULL,
3526
3614
                    sepnew=NULL;
3527
3615
  Uint2             entityID,
3536
3624
  TAlignmentFilePtr afp;
3537
3625
  Uint1             moltype;
3538
3626
  ErrSev            sev;
 
3627
  SeqEntryPtr       scope;
 
3628
  SeqAlignPtr       salp_copy;
 
3629
  BioseqSetPtr      bssp = NULL;
3539
3630
   
3540
3631
  ompcp = (OMProcControlPtr) data;
3541
3632
  if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
3549
3640
      break;
3550
3641
    case OBJ_BIOSEQSET :
3551
3642
      sep = SeqMgrGetSeqEntryForData (ompcp->input_data);
 
3643
      bssp = (BioseqSetPtr) ompcp->input_data;
3552
3644
      break;
3553
3645
    case OBJ_SEQENTRY :
3554
3646
      sep = ompcp->input_data;
3603
3695
    if (salpnew) {
3604
3696
      sev = ErrSetMessageLevel (SEV_FATAL);
3605
3697
   
 
3698
      scope = SeqEntrySetScope (NULL);
3606
3699
      /* adjust the start positions for the sequences read in from the alignments. */
3607
3700
      CalculateAlignmentOffsets (sepnew, sep);
3608
3701
      /* ValidateSeqAlignandACCInSeqEntry will readjust the start positions for
3609
3702
       * the alignments for far pointer sequences.
3610
3703
       */
 
3704
      SeqEntrySetScope (scope);
3611
3705
      ok = ValidateSeqAlignandACCInSeqEntry (sepnew, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE);
3612
 
 
 
3706
      
3613
3707
      ErrSetMessageLevel (sev);
 
3708
      
3614
3709
      if (ok) {
 
3710
        /* if there is already an alignment, ask if the user wants to remove the old
 
3711
         * one before adding the new alignment.
 
3712
         */
3615
3713
        salp = (SeqAlignPtr) FindSeqAlignInSeqEntry (sep, OBJ_SEQALIGN);
3616
3714
        if (salp) 
3617
3715
        {
3621
3719
            SeqEntryExplore (sep, &dirty, SqnSeqAlignDeleteInSeqEntryCallBack);
3622
3720
          }
3623
3721
        }
3624
 
           
3625
 
        sap=SeqAnnotForSeqAlign(salpnew);
3626
 
        sapcopy = (SeqAnnotPtr) AsnIoMemCopy (sap, (AsnReadFunc) SeqAnnotAsnRead, (AsnWriteFunc) SeqAnnotAsnWrite);
3627
 
           
3628
 
        SeqAlignAddInSeqEntry (sep, sapcopy);
3629
 
        sap->data=NULL;
3630
 
        MemFree(sap); 
 
3722
 
 
3723
        /* make a copy of the alignment in sepnew - the alignment in sepnew will
 
3724
         * be freed when sepnew is freed.
 
3725
         */
 
3726
        salp_copy = (SeqAlignPtr) AsnIoMemCopy (salpnew, (AsnReadFunc) SeqAlignAsnRead,
 
3727
                                                       (AsnWriteFunc) SeqAlignAsnWrite);
 
3728
        /* the copy function doesn't copy the index, so the alignment must be
 
3729
         * indexed now.
 
3730
         */
 
3731
        AlnMgr2IndexSeqAlignEx(salp_copy, FALSE);
 
3732
        /* break the alignment at gaps, if the set contains any delta sequences */
 
3733
        salp_copy = MakeDiscontiguousAlignments (salp_copy);
 
3734
          
 
3735
        /* break the chain of alignments and create separate SeqAnnots for each one */
 
3736
        CreateSeqAnnotsForDiscontiguousAlignments (salp_copy, entityID, bssp); 
3631
3737
        ObjMgrSetDirtyFlag (entityID, TRUE);
3632
3738
        itemID = GetItemIDGivenPointer (entityID, OBJ_SEQENTRY, (Pointer) sep);
3633
3739
        ObjMgrSendMsg (OM_MSG_UPDATE, entityID, itemID, OBJ_SEQENTRY);
3639
3745
  return OM_MSG_RET_OK;
3640
3746
}
3641
3747
 
 
3748
static Boolean IsIntervalGap (BioseqPtr bsp, Int4 start, Int4 stop)
 
3749
{
 
3750
  DeltaSeqPtr dsp;
 
3751
  SeqLitPtr   litp;
 
3752
  SeqLocPtr   loc;
 
3753
  Int4        seq_offset = 0, len;
 
3754
  Boolean     interval_in_gap = TRUE;
 
3755
  Boolean     this_is_gap;
 
3756
  
 
3757
  if (bsp == NULL 
 
3758
      || bsp->repr != Seq_repr_delta 
 
3759
      || bsp->seq_ext_type != 4
 
3760
      || start < 0
 
3761
      || stop >= bsp->length)
 
3762
  {
 
3763
    return FALSE;
 
3764
  }
 
3765
  
 
3766
  for (dsp = (DeltaSeqPtr) bsp->seq_ext;
 
3767
       dsp != NULL && dsp->next != NULL && seq_offset < stop; 
 
3768
       dsp = dsp->next) 
 
3769
  {
 
3770
    len = 0;
 
3771
    this_is_gap = FALSE;
 
3772
    if (dsp->choice == 1)
 
3773
    {
 
3774
      loc = (SeqLocPtr) dsp->data.ptrvalue;
 
3775
      len = SeqLocLen (loc);
 
3776
    }
 
3777
    else if (dsp->choice == 2)
 
3778
    {
 
3779
      litp = (SeqLitPtr) dsp->data.ptrvalue;
 
3780
      if (litp != NULL)
 
3781
      {
 
3782
        len = litp->length;
 
3783
        if (litp->seq_data == NULL)
 
3784
        {
 
3785
          this_is_gap = TRUE;
 
3786
        }
 
3787
      }
 
3788
    }
 
3789
    
 
3790
    if (seq_offset <= start && seq_offset + len >= stop)
 
3791
    {
 
3792
      return this_is_gap;
 
3793
    }
 
3794
    else if ((seq_offset <= start && seq_offset + len > start)
 
3795
             || (seq_offset < stop && seq_offset + len > stop)
 
3796
             || (seq_offset >= start && seq_offset + len <= stop))
 
3797
    {
 
3798
      if (!this_is_gap)
 
3799
      {
 
3800
        return FALSE;
 
3801
      }
 
3802
    }
 
3803
    seq_offset += len;
 
3804
  }
 
3805
  return TRUE;
 
3806
}
 
3807
 
 
3808
static Boolean 
 
3809
CollapseTwoGapSegments 
 
3810
(DenseSegPtr    dsp, 
 
3811
 Int4           seg_num_first, 
 
3812
 BioseqPtr PNTR bsparray)
 
3813
{
 
3814
  Int4Ptr  newstarts;
 
3815
  Int4Ptr  newlens;
 
3816
  Uint1Ptr newstrands = NULL; 
 
3817
  Int4     row_num, seg_num;
 
3818
  
 
3819
  if (dsp == NULL || seg_num_first > dsp->numseg - 2)
 
3820
  {
 
3821
    return FALSE;
 
3822
  }
 
3823
  
 
3824
  if (dsp->lens [seg_num_first] != dsp->lens [seg_num_first + 1])
 
3825
  {
 
3826
    return FALSE;
 
3827
  }
 
3828
  
 
3829
  for (row_num = 0; row_num < dsp->dim; row_num++)
 
3830
  {
 
3831
    if (dsp->starts [seg_num_first * dsp->dim + row_num] != -1
 
3832
        && dsp->starts [(seg_num_first + 1) * dsp->dim + row_num] != -1)
 
3833
    {
 
3834
      return FALSE;
 
3835
    }
 
3836
    
 
3837
    /* segment must be over a gap for all rows not in gap */
 
3838
    /* for the first segment */
 
3839
    if (dsp->starts [seg_num_first * dsp->dim + row_num] != -1 
 
3840
        && ! IsIntervalGap (bsparray[row_num], 
 
3841
                            dsp->starts [seg_num_first * dsp->dim + row_num], 
 
3842
                            dsp->starts [seg_num_first * dsp->dim + row_num] + dsp->lens[seg_num_first]))
 
3843
 
 
3844
    {
 
3845
      return FALSE;
 
3846
    }
 
3847
    /* and for the second segment */
 
3848
    if (dsp->starts [(seg_num_first + 1) * dsp->dim + row_num] != -1 
 
3849
        && ! IsIntervalGap (bsparray[row_num], 
 
3850
                            dsp->starts [(seg_num_first + 1) * dsp->dim + row_num], 
 
3851
                            dsp->starts [(seg_num_first + 1) * dsp->dim + row_num] + dsp->lens[seg_num_first + 1]))
 
3852
 
 
3853
    {
 
3854
      return FALSE;
 
3855
    }
 
3856
  }
 
3857
  
 
3858
  newstarts = (Int4Ptr) MemNew (sizeof (Int4) * dsp->dim * (dsp->numseg - 1));
 
3859
  newlens = (Int4Ptr) MemNew (sizeof (Int4) * (dsp->numseg - 1));
 
3860
  if (dsp->strands != NULL)
 
3861
  {
 
3862
    newstrands = (Uint1Ptr) MemNew (sizeof (Uint1) * dsp->dim * (dsp->numseg - 1));
 
3863
  }
 
3864
  
 
3865
  /* copy the portion of the alignment before the segments to be collapsed */
 
3866
  for (seg_num = 0; seg_num < seg_num_first; seg_num++)
 
3867
  {
 
3868
    for (row_num = 0; row_num < dsp->dim; row_num++)
 
3869
    {
 
3870
      newstarts [seg_num * dsp->dim + row_num] = dsp->starts [seg_num * dsp->dim + row_num];
 
3871
      if (dsp->strands != NULL)
 
3872
      {
 
3873
        newstrands [seg_num * dsp->dim + row_num] = dsp->strands[seg_num * dsp->dim + row_num];
 
3874
      }
 
3875
    }
 
3876
    newlens[seg_num] = dsp->lens[seg_num];
 
3877
  }
 
3878
  
 
3879
  /* collapse the two segments */
 
3880
  for (row_num = 0; row_num < dsp->dim; row_num++)
 
3881
  {
 
3882
    if (dsp->starts [seg_num * dsp->dim + row_num] == -1)
 
3883
    {
 
3884
      newstarts [seg_num * dsp->dim + row_num] = dsp->starts [(seg_num + 1) * dsp->dim + row_num];
 
3885
      if (dsp->strands != NULL)
 
3886
      {
 
3887
        newstrands [seg_num * dsp->dim + row_num] = dsp->strands [(seg_num + 1) * dsp->dim + row_num];
 
3888
      }
 
3889
    }
 
3890
    else
 
3891
    {
 
3892
      newstarts [seg_num * dsp->dim + row_num] = dsp->starts [seg_num * dsp->dim + row_num];
 
3893
      if (dsp->strands != NULL)
 
3894
      {
 
3895
        newstrands [seg_num * dsp->dim + row_num] = dsp->strands [seg_num * dsp->dim + row_num];
 
3896
      }
 
3897
    }
 
3898
  }
 
3899
  newlens [seg_num] = dsp->lens [seg_num];
 
3900
  seg_num++;
 
3901
  
 
3902
  /* copy the remaining segments after the collapsed pair */
 
3903
  while (seg_num < dsp->numseg - 1)
 
3904
  {
 
3905
    for (row_num = 0; row_num < dsp->dim; row_num++)
 
3906
    {
 
3907
      newstarts [seg_num * dsp->dim + row_num] = dsp->starts [(seg_num + 1) * dsp->dim + row_num];
 
3908
      if (dsp->strands != NULL)
 
3909
      {
 
3910
        newstrands [seg_num * dsp->dim + row_num] = dsp->strands[(seg_num + 1) * dsp->dim + row_num];
 
3911
      }
 
3912
    }
 
3913
    newlens[seg_num] = dsp->lens[(seg_num + 1)];
 
3914
    seg_num++;
 
3915
  }
 
3916
 
 
3917
  /* replace the starts, strands, lens, and numseg in dsp */
 
3918
  dsp->starts = MemFree (dsp->starts);
 
3919
  dsp->starts = newstarts;
 
3920
  dsp->strands = MemFree (dsp->strands);
 
3921
  dsp->strands = newstrands;
 
3922
  dsp->lens = MemFree (dsp->lens);
 
3923
  dsp->lens = newlens;  
 
3924
  dsp->numseg--;
 
3925
  return TRUE;
 
3926
}
 
3927
 
 
3928
extern void ConsolidateSegmentsOverKnownLengthGaps (SeqAlignPtr salp)
 
3929
{
 
3930
  DenseSegPtr    dsp;
 
3931
  SeqIdPtr       sip;
 
3932
  BioseqPtr PNTR bsparray;
 
3933
  Int4           row_num, seg_num;
 
3934
  
 
3935
  if (salp == NULL || salp->segtype != SAS_DENSEG || salp->segs == NULL)
 
3936
  {
 
3937
    return;
 
3938
  }
 
3939
 
 
3940
  if (salp->saip != NULL)
 
3941
  {
 
3942
    SeqAlignIndexFree(salp->saip);
 
3943
    salp->saip = NULL;
 
3944
  }
 
3945
  
 
3946
  dsp = (DenseSegPtr) salp->segs;
 
3947
  
 
3948
  bsparray = (BioseqPtr PNTR) MemNew (sizeof (BioseqPtr) * dsp->dim);
 
3949
  
 
3950
  
 
3951
  for (sip = dsp->ids, row_num = 0;
 
3952
       sip != NULL && row_num < dsp->dim;
 
3953
       sip = sip->next, row_num++)
 
3954
  {
 
3955
    bsparray [row_num] = BioseqFind (sip);
 
3956
  }
 
3957
  
 
3958
  seg_num = 0;
 
3959
  while (seg_num < dsp->numseg - 1)
 
3960
  {
 
3961
    if (!CollapseTwoGapSegments (dsp, seg_num, bsparray))
 
3962
    {
 
3963
      seg_num++;
 
3964
    }
 
3965
  }
 
3966
  
 
3967
  AlnMgr2IndexSeqAlignEx(salp, FALSE);
 
3968
  bsparray = MemFree (bsparray); 
 
3969
}
 
3970
 
 
3971
static Int2 LIBCALLBACK ConsolidateGapGaps (Pointer data)
 
3972
 
 
3973
{
 
3974
  OMProcControlPtr  ompcp;
 
3975
  SeqAlignPtr       salp=NULL;
 
3976
  Uint2             entityID;
 
3977
  SeqAnnotPtr       sanp_old;
 
3978
   
 
3979
  ompcp = (OMProcControlPtr) data;
 
3980
  if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
 
3981
 
 
3982
  if (ompcp->input_data == NULL) return OM_MSG_RET_ERROR;
 
3983
 
 
3984
  switch(ompcp->input_itemtype)
 
3985
    {
 
3986
    case OBJ_SEQALIGN :
 
3987
      salp = (SeqAlignPtr) ompcp->input_data;
 
3988
      break;
 
3989
    case OBJ_SEQANNOT:
 
3990
      sanp_old = (SeqAnnotPtr) ompcp->input_data;
 
3991
      if (sanp_old->type == 2)
 
3992
      {
 
3993
        salp = sanp_old->data;
 
3994
      }
 
3995
      break;
 
3996
    default :
 
3997
      return OM_MSG_RET_ERROR;
 
3998
  }
 
3999
  if (salp==NULL)
 
4000
     return OM_MSG_RET_ERROR;
 
4001
  entityID = ompcp->input_entityID;
 
4002
  if (entityID < 1)
 
4003
     return OM_MSG_RET_ERROR;
 
4004
  
 
4005
  ConsolidateSegmentsOverKnownLengthGaps (salp);
 
4006
  
 
4007
  ObjMgrSetDirtyFlag (entityID, TRUE);
 
4008
  
 
4009
  ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
4010
  
 
4011
  return OM_MSG_RET_OK;
 
4012
}
 
4013
 
 
4014
 
 
4015
/* NOTE - need to call DeleteMarkedObjects after calling this function */
 
4016
extern void FixOneAlignmentOverGaps (SeqAlignPtr salp, Uint2 entityID)
 
4017
{
 
4018
  SeqAnnotPtr       sanp_old, sanp_new;
 
4019
  SeqAlignPtr       salp_copy, salp_tmp;
 
4020
  BioseqSetPtr      bssp = NULL;
 
4021
  
 
4022
  sanp_old = GetSeqAnnotForAlignment (salp);
 
4023
  if (sanp_old == NULL)
 
4024
  {
 
4025
     return;
 
4026
  }
 
4027
  
 
4028
  if (sanp_old->idx.parenttype == OBJ_BIOSEQSET)
 
4029
  {
 
4030
    bssp = (BioseqSetPtr) sanp_old->idx.parentptr;
 
4031
  }
 
4032
  
 
4033
  /* make a copy of the alignment */
 
4034
  salp_copy = (SeqAlignPtr) AsnIoMemCopy (salp, (AsnReadFunc) SeqAlignAsnRead,
 
4035
                                                       (AsnWriteFunc) SeqAlignAsnWrite);
 
4036
  /* the copy function doesn't copy the index, so the alignment must be
 
4037
   * indexed now.
 
4038
   */
 
4039
  AlnMgr2IndexSeqAlignEx(salp_copy, FALSE);
 
4040
  /* break the alignment at gaps, if the set contains any delta sequences */
 
4041
  salp_copy = MakeDiscontiguousAlignments (salp_copy);
 
4042
  
 
4043
  for (salp_tmp = salp_copy; salp_tmp != NULL; salp_tmp = salp_tmp->next)
 
4044
  {
 
4045
     NoMoreSegGapForOneAlignment (salp_tmp, NULL);
 
4046
  }
 
4047
          
 
4048
  /* break the chain of alignments and create separate SeqAnnots for each one */
 
4049
  CreateSeqAnnotsForDiscontiguousAlignments (salp_copy, entityID, bssp); 
 
4050
 
 
4051
  /* need to index the alignments before we can find the new alignment and remove the old */
 
4052
  ObjMgrSetDirtyFlag (entityID, TRUE);  
 
4053
  ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
4054
  
 
4055
  sanp_new = GetSeqAnnotForAlignment (salp_copy);
 
4056
  
 
4057
  if (sanp_new != NULL)
 
4058
  {
 
4059
    salp->idx.deleteme = TRUE;
 
4060
  }  
 
4061
}
 
4062
 
 
4063
static Int2 LIBCALLBACK FixAlignmentOverGaps (Pointer data)
 
4064
 
 
4065
{
 
4066
  OMProcControlPtr  ompcp;
 
4067
  SeqAlignPtr       salp=NULL;
 
4068
  Uint2             entityID;
 
4069
  SeqAnnotPtr       sanp_old;
 
4070
   
 
4071
  ompcp = (OMProcControlPtr) data;
 
4072
  if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
 
4073
 
 
4074
  if (ompcp->input_data == NULL) return OM_MSG_RET_ERROR;
 
4075
 
 
4076
  switch(ompcp->input_itemtype)
 
4077
    {
 
4078
    case OBJ_SEQALIGN :
 
4079
      salp = (SeqAlignPtr) ompcp->input_data;
 
4080
      break;
 
4081
    case OBJ_SEQANNOT:
 
4082
      sanp_old = (SeqAnnotPtr) ompcp->input_data;
 
4083
      if (sanp_old->type == 2)
 
4084
      {
 
4085
        salp = sanp_old->data;
 
4086
      }
 
4087
      break;
 
4088
    default :
 
4089
      return OM_MSG_RET_ERROR;
 
4090
  }
 
4091
  if (salp==NULL)
 
4092
     return OM_MSG_RET_ERROR;
 
4093
  entityID = ompcp->input_entityID;
 
4094
  if (entityID < 1)
 
4095
     return OM_MSG_RET_ERROR;
 
4096
  
 
4097
  FixOneAlignmentOverGaps (salp, entityID);
 
4098
  DeleteMarkedObjects (entityID, 0, NULL);
 
4099
  
 
4100
  ObjMgrSetDirtyFlag (entityID, TRUE);
 
4101
  
 
4102
  ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
4103
  
 
4104
  return OM_MSG_RET_OK;
 
4105
}
 
4106
 
 
4107
 
3642
4108
typedef struct sqn_bsp {
3643
4109
   BioseqPtr  bsp;
3644
4110
   struct sqn_bsp PNTR next;
3901
4367
static void GetBadSequencesAndReversals 
3902
4368
(SQNBspPtr       sbp, 
3903
4369
 Uint2           entityID,
 
4370
 Boolean         use_new_blast,
3904
4371
 BoolPtr         some_reversed,
3905
4372
 Int4Ptr         num_seqs,
3906
4373
 ValNodePtr PNTR good_list_ptr,
3931
4398
      (*num_seqs) ++;
3932
4399
    }
3933
4400
    revcomp = FALSE;
3934
 
    salp = Sqn_GlobalAlign2Seq(sbp->bsp, sbp_idx->bsp, &revcomp);
 
4401
    if (use_new_blast)
 
4402
    {
 
4403
      salp = Sequin_GlobalAlign2Seq(sbp->bsp, sbp_idx->bsp, &revcomp);
 
4404
    }
 
4405
    else
 
4406
    {
 
4407
      salp = Sqn_GlobalAlign2Seq(sbp->bsp, sbp_idx->bsp, &revcomp);
 
4408
    }
3935
4409
    if (salp == NULL || ! ValidateSeqAlign (salp, entityID, FALSE, FALSE, TRUE, FALSE, FALSE, &dirty))
3936
4410
    {
3937
4411
      tmp_id = SeqIdDup (SeqIdFindBest (sbp_idx->bsp->id, 0));
4499
4973
}
4500
4974
 
4501
4975
static Int2 CreateOneAlignment 
4502
 
(SQNBspPtr sbp, 
4503
 
 Uint2     entityID,
4504
 
 FILE      *fp,
4505
 
 BoolPtr   errors_in_log)
 
4976
(SQNBspPtr    sbp, 
 
4977
 Uint2        entityID,
 
4978
 BioseqSetPtr bssp,
 
4979
 Boolean      use_new_blast,
 
4980
 FILE         *fp,
 
4981
 BoolPtr      errors_in_log)
4506
4982
{
4507
4983
  BioseqPtr         master_bsp;
4508
4984
  Boolean           some_reversed;
4519
4995
  SQNBspPtr         sbp_prev;
4520
4996
  Boolean           dirty;
4521
4997
  DenseSegPtr       dsp;
4522
 
  SeqAnnotPtr       sap;
4523
 
  SeqEntryPtr       sep;
4524
 
  SeqAnnotPtr PNTR  sapp;
4525
 
  BioseqSetPtr      bssp;
4526
 
  SeqAnnotPtr       curr;
4527
4998
  ValNodePtr        vnp;
4528
4999
  Int4              num_reversed = 0;
4529
5000
  
4530
5001
  if (sbp == NULL || errors_in_log == NULL) return OM_MSG_RET_ERROR;
4531
5002
 
4532
5003
  master_bsp = sbp->bsp;
4533
 
  GetBadSequencesAndReversals (sbp, entityID, &some_reversed, &num_seqs, &good_list, &bad_list);
 
5004
  GetBadSequencesAndReversals (sbp, entityID, use_new_blast, &some_reversed, &num_seqs, &good_list, &bad_list);
4534
5005
  continue_with_bad = ContinueWithBadSequences(bad_list, num_seqs);
4535
5006
  if (continue_with_bad != ANS_YES)
4536
5007
  {
4565
5036
     * of the top of the list if necessary.
4566
5037
     */
4567
5038
    revcomp = FALSE;
4568
 
    salp = Sqn_GlobalAlign2Seq(master_bsp, sbp->bsp, &revcomp);
 
5039
    if (use_new_blast)
 
5040
    {
 
5041
      salp = Sequin_GlobalAlign2Seq(master_bsp, sbp->bsp, &revcomp);
 
5042
    }
 
5043
    else
 
5044
    {
 
5045
      salp = Sqn_GlobalAlign2Seq(master_bsp, sbp->bsp, &revcomp);
 
5046
    }
4569
5047
    SeqAlignFree (salp); 
4570
5048
    if (revcomp)
4571
5049
    {
4597
5075
       sip1 = SeqIdDup(bsp->id);
4598
5076
       sip2 = SeqIdDup(sbp->bsp->id);
4599
5077
       revcomp = FALSE;
4600
 
       salp = Sqn_GlobalAlign2Seq(bsp, sbp->bsp, &revcomp);
 
5078
       if (use_new_blast)
 
5079
       {
 
5080
         salp = Sequin_GlobalAlign2Seq(bsp, sbp->bsp, &revcomp);
 
5081
       }
 
5082
       else
 
5083
       {
 
5084
         salp = Sqn_GlobalAlign2Seq(bsp, sbp->bsp, &revcomp);        
 
5085
       }
4601
5086
       
4602
5087
       /* count the number of sequences we are trying to align */
4603
5088
       num_seqs ++;
4685
5170
 
4686
5171
    ValidateSeqAlign (salp_mult, entityID, TRUE, FALSE, TRUE, FALSE, FALSE, &dirty);
4687
5172
    SeqAlignSetFree(salp_head);
4688
 
    sap = SeqAnnotForSeqAlign(salp_mult);
 
5173
    
 
5174
    /* index multiple alignment */
 
5175
    AlnMgr2IndexSeqAlignEx(salp_mult, FALSE);
 
5176
    
 
5177
    /* break up alignment if it covers gaps of unknown length */
 
5178
    salp_mult = MakeDiscontiguousAlignments (salp_mult);
 
5179
    
4689
5180
  } else
4690
 
    sap = NULL;
4691
 
  if (sap != NULL) {
4692
 
 
4693
 
    sep = GetTopSeqEntryForEntityID (entityID);
4694
 
    if (sep != NULL && sep->data.ptrvalue != NULL) {
4695
 
      sapp = NULL;
4696
 
      if (IS_Bioseq (sep)) {
4697
 
        bsp = (BioseqPtr) sep->data.ptrvalue;
4698
 
        sapp = &(bsp->annot);
4699
 
      } else if (IS_Bioseq_set (sep)) {
4700
 
        bssp = (BioseqSetPtr) sep->data.ptrvalue;
4701
 
        sapp = &(bssp->annot);
4702
 
      }
4703
 
      if (sapp != NULL) {
4704
 
        if (*sapp != NULL) {
4705
 
          curr = *sapp;
4706
 
          while (curr->next != NULL) {
4707
 
            curr = curr->next;
4708
 
          }
4709
 
          curr->next = sap;
4710
 
        } else {
4711
 
          *sapp = sap;
4712
 
        }
4713
 
      }
4714
 
      ObjMgrSetDirtyFlag (entityID, TRUE);
4715
 
      ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
4716
 
    }
 
5181
    salp_mult = NULL;
 
5182
  
 
5183
  if (salp_mult != NULL)
 
5184
  {
 
5185
    /* create separate SeqAnnots for each alignment in the chain */
 
5186
    CreateSeqAnnotsForDiscontiguousAlignments (salp_mult, entityID, bssp);
 
5187
    ObjMgrSetDirtyFlag (entityID, TRUE);
 
5188
    ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
4717
5189
  }
4718
5190
  if (num_reversed > 0)
4719
5191
  {
4829
5301
4830
5302
 
4831
5303
 
4832
 
static Int2 LIBCALLBACK GenerateSeqAlignFromSeqEntryMasterOption (Pointer data, Boolean choose_master) 
 
5304
static Int2 LIBCALLBACK 
 
5305
GenerateSeqAlignFromSeqEntryMasterOption 
 
5306
(Pointer data, 
 
5307
 Boolean choose_master,
 
5308
 Boolean use_new_blast) 
4833
5309
 
4834
5310
{
4835
5311
  OMProcControlPtr  ompcp;
4878
5354
  {
4879
5355
    sbp = vnp->data.ptrvalue;
4880
5356
    if (sbp == NULL) continue;
4881
 
    CreateOneAlignment (sbp, ompcp->input_entityID, fp, &errors_in_log);
 
5357
    CreateOneAlignment (sbp, ompcp->input_entityID, bssp, use_new_blast, fp, &errors_in_log);
4882
5358
  }
4883
5359
  
4884
5360
  FileClose (fp);
4893
5369
static Int2 LIBCALLBACK GenerateSeqAlignFromSeqEntry (Pointer data) 
4894
5370
 
4895
5371
{
4896
 
  return GenerateSeqAlignFromSeqEntryMasterOption (data, FALSE);
 
5372
  return GenerateSeqAlignFromSeqEntryMasterOption (data, FALSE, FALSE);
4897
5373
}
4898
5374
 
4899
5375
static Int2 LIBCALLBACK GenerateSeqAlignFromSeqEntryChooseMaster (Pointer data) 
4900
5376
 
4901
5377
{
4902
 
  return GenerateSeqAlignFromSeqEntryMasterOption (data, TRUE);
4903
 
}
4904
 
 
4905
 
static Int2 LIBCALLBACK GenerateSeqAlignFromSeqEntryProt (Pointer data)
 
5378
  return GenerateSeqAlignFromSeqEntryMasterOption (data, TRUE, FALSE);
 
5379
}
 
5380
 
 
5381
static Int2 LIBCALLBACK GenerateSeqAlignFromSeqEntryUseNewBlast (Pointer data) 
 
5382
 
 
5383
{
 
5384
  return GenerateSeqAlignFromSeqEntryMasterOption (data, FALSE, TRUE);
 
5385
}
 
5386
 
 
5387
static Int2 LIBCALLBACK GenerateSeqAlignFromSeqEntryChooseMasterUseNewBlast (Pointer data) 
 
5388
 
 
5389
{
 
5390
  return GenerateSeqAlignFromSeqEntryMasterOption (data, TRUE, TRUE);
 
5391
}
 
5392
 
 
5393
static Int2 LIBCALLBACK GenerateSeqAlignFromSeqEntryProtEx (Pointer data, Boolean use_new_blast)
4906
5394
 
4907
5395
{
4908
5396
  BioseqPtr         bsp;
4947
5435
  salp_head = salp_prev = NULL;
4948
5436
  while (sbp != NULL)
4949
5437
  {
4950
 
    salp = Sqn_GlobalAlign2Seq(bsp, sbp->bsp, FALSE);
 
5438
    if (use_new_blast)
 
5439
    {
 
5440
      salp = Sequin_GlobalAlign2Seq(bsp, sbp->bsp, FALSE);
 
5441
    }
 
5442
    else
 
5443
    {
 
5444
      salp = Sqn_GlobalAlign2Seq(bsp, sbp->bsp, FALSE);
 
5445
    }
4951
5446
    if (salp_head != NULL && salp != NULL)
4952
5447
    {
4953
5448
       salp_prev->next = salp;
5025
5520
}
5026
5521
 
5027
5522
 
 
5523
static Int2 LIBCALLBACK GenerateSeqAlignFromSeqEntryProt (Pointer data)
 
5524
{
 
5525
  return GenerateSeqAlignFromSeqEntryProtEx (data, FALSE);
 
5526
}
 
5527
 
 
5528
static Int2 LIBCALLBACK GenerateSeqAlignFromSeqEntryProtUseNewBlast (Pointer data)
 
5529
{
 
5530
  return GenerateSeqAlignFromSeqEntryProtEx (data, TRUE);
 
5531
}
 
5532
 
5028
5533
static Boolean RawSeqLaunchFunc (GatherContextPtr gcp)
5029
5534
 
5030
5535
{
7207
7712
  ans = Message (MSG_OKC, "Are you sure you want to convert alignment GIs to accessions?");
7208
7713
  if (ans == ANS_CANCEL) return OM_MSG_RET_DONE;
7209
7714
  sep = GetTopSeqEntryForEntityID (ompcp->input_entityID);
7210
 
  LookupFarSeqIDs (sep, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE);
 
7715
  LookupFarSeqIDs (sep, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE);
7211
7716
  MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
7212
7717
  gs.seglevels = 1;
7213
7718
  gs.get_feats_location = FALSE;
7301
7806
  ans = Message (MSG_OKC, "Are you sure you want to convert alignment accessions to GIs?");
7302
7807
  if (ans == ANS_CANCEL) return OM_MSG_RET_DONE;
7303
7808
  sep = GetTopSeqEntryForEntityID (ompcp->input_entityID);
7304
 
  LookupFarSeqIDs (sep, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE);
 
7809
  LookupFarSeqIDs (sep, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE);
7305
7810
  MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
7306
7811
  gs.seglevels = 1;
7307
7812
  gs.get_feats_location = FALSE;
7410
7915
        annot = SeqAnnotNew ();
7411
7916
        if (annot != NULL) {
7412
7917
          annot->type = 2;
7413
 
          adp = ValNodeNew (NULL);
 
7918
          adp = AnnotDescrNew (NULL);
7414
7919
          adp->choice = Annot_descr_user;
7415
7920
          annot->desc = adp;
7416
7921
          uop = UserObjectNew ();
7484
7989
  ompcp = (OMProcControlPtr) data;
7485
7990
  if (ompcp == NULL) return OM_MSG_RET_ERROR;
7486
7991
  sep = GetTopSeqEntryForEntityID (ompcp->input_entityID);
7487
 
  LookupFarSeqIDs (sep, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE);
 
7992
  LookupFarSeqIDs (sep, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE);
7488
7993
  VisitAnnotsInSep (sep, NULL, FindBlastNR);
7489
7994
  DeleteMarkedObjects (ompcp->input_entityID, 0, NULL);
7490
7995
  ObjMgrSetDirtyFlag (ompcp->input_entityID, TRUE);
9816
10321
    REGISTER_SEPARATE_MRNA_ALIGNS;
9817
10322
    REGISTER_SEQUIN_ACCN_TO_GI;
9818
10323
    REGISTER_SEQUIN_GI_TO_ACCN;
 
10324
    REGISTER_GENOMEPROJSDBUSER_DESC_EDIT;
9819
10325
    REGISTER_REFGENEUSER_DESC_EDIT;
9820
10326
    REGISTER_PROT_IDS_TO_GENE_SYN;
 
10327
    REGISTER_COPY_MASTER_SOURCE_TO_SEGMENTS;
9821
10328
    REGISTER_DESCRIPTOR_PROPAGATE;
9822
10329
  }
9823
10330
 
9848
10355
  REGISTER_MAP_TO_PROT;
9849
10356
  REGISTER_MAP_TO_NUC;
9850
10357
 
 
10358
  REGISTER_FIX_ALIGNMENT_GAP_GAPS;
 
10359
  REGISTER_FIX_ALIGNMENT_OVER_GAPS;
9851
10360
  REGISTER_UPDATE_SEQALIGN;
9852
10361
  REGISTER_PARTSEQALIGNTOPARENT;
9853
10362
  REGISTER_CONVERTTOSEGSETALIGN;
9854
10363
  REGISTER_CONVERTSEQALIGN;
 
10364
  REGISTER_MAKESEQALIGNMASTERNEWBLAST;
9855
10365
  REGISTER_MAKESEQALIGNMASTER;
 
10366
  REGISTER_MAKESEQALIGNNEWBLAST;
9856
10367
  REGISTER_MAKESEQALIGN;
 
10368
  REGISTER_MAKESEQALIGNPNEWBLAST;
9857
10369
  REGISTER_MAKESEQALIGNP;
9858
10370
  REGISTER_NORMSEQALIGN;
9859
10371
  REGISTER_NOMORESEGGAP;
9881
10393
    /*
9882
10394
    REGISTER_FEAT_INTERVALS_TO_DELTA;
9883
10395
    */
 
10396
    REGISTER_REORDER_BY_ID;
9884
10397
    REGISTER_CONVERT_TO_DELTA;
9885
10398
    REGISTER_DELETE_BY_TEXT;
9886
10399
    REGISTER_SEGREGATE_BY_MOLECULE_TYPE;
10944
11457
  {
10945
11458
    len_match = StringLen (*ptr);
10946
11459
    if (len_match < best_len && StringCmp (*ptr, "USA") != 0) continue;
10947
 
    cp = StringStr (find_str, *ptr);
 
11460
    cp = StringISearch (find_str, *ptr);
10948
11461
    /* if no match at all, continue */
10949
11462
    if (cp == NULL) continue;
10950
11463
    /* if character after match is alpha, continue */
11055
11568
        if (cp == ssp->name)
11056
11569
  {
11057
11570
    len_after = len_qual - len_state;
11058
 
    newname = (CharPtr) MemNew ((3 + len_country + len_state + len_after) * sizeof (Char));
 
11571
    newname = (CharPtr) MemNew ((5 + len_country + len_state + len_after) * sizeof (Char));
11059
11572
    sprintf (newname, "%s: %s", country_name, state_name);
11060
11573
    if (len_after > 0)
11061
11574
    {
 
11575
      StringCat (newname, ", ");
11062
11576
      StringCat (newname, ssp->name + len_state);
11063
11577
    }
11064
11578
    ssp->name = MemFree (ssp->name);
11066
11580
  }
11067
11581
  else
11068
11582
  {
11069
 
    newname = (CharPtr) MemNew (len_qual + 4 + len_country);
 
11583
    newname = (CharPtr) MemNew (len_qual + 5 + len_country);
11070
11584
    *(cp - 1) = 0;
11071
11585
    before = StringSave (ssp->name);
11072
 
    sprintf (newname, "%s: %s ", country_name, state_name);
11073
 
    StringNCpy (newname + 3 + len_country + len_state, before, StringLen (before));
11074
 
    StringCpy (newname + 3 + len_country + len_state + StringLen (before), cp + len_state);
 
11586
    sprintf (newname, "%s: %s, ", country_name, state_name);
 
11587
    StringNCpy (newname + 4 + len_country + len_state, before, StringLen (before));
 
11588
    StringCpy (newname + 4 + len_country + len_state + StringLen (before), cp + len_state);
11075
11589
    len_name = StringLen (newname);
11076
11590
    while (isspace ((Int4)(newname[len_name - 1])) || ispunct ((Int4)(newname [len_name - 1])))
11077
11591
    {
11078
11592
        newname [len_name - 1] = 0;
11079
11593
          len_name --;
11080
11594
    }
 
11595
    /* get rid of trailing comma if necessary */
 
11596
    if (len_name == StringLen (country_name) + 3 + StringLen (state_name)
 
11597
        && newname [len_name - 1] == ',')
 
11598
    {
 
11599
        newname [len_name - 1] = 0;
 
11600
          len_name --;
 
11601
    }
11081
11602
    before = MemFree (before);
11082
11603
    MemFree (ssp->name);
11083
11604
    ssp->name = newname;
11094
11615
  FindReplaceString (&(ssp->name), "Vietnam", "Viet Nam", FALSE, TRUE);
11095
11616
  FindReplaceString (&(ssp->name), "Ivory Coast", "Cote d'Ivoire", FALSE, TRUE);
11096
11617
  FindReplaceString (&(ssp->name), "UK", "United Kingdom", FALSE, TRUE);
 
11618
  FindReplaceString (&(ssp->name), "United States of America", "USA", FALSE, TRUE);
 
11619
  FindReplaceString (&(ssp->name), "United States", "USA", FALSE, TRUE);
 
11620
  FindReplaceString (&(ssp->name), "U.S.A.", "USA", FALSE, TRUE);
 
11621
}
 
11622
 
 
11623
static CharPtr MoveStateAndAddComma (CharPtr cntry_str, CharPtr state_match, Int4 len_cntry)
 
11624
{
 
11625
  CharPtr newname = NULL, cp;
 
11626
  Int4    len_state, len_qual, len_after, len_before;
 
11627
  
 
11628
  if (StringHasNoText (cntry_str) || StringHasNoText (state_match) || len_cntry < 1)
 
11629
  {
 
11630
    return cntry_str;
 
11631
  }
 
11632
  
 
11633
  cp = StringISearch (cntry_str + len_cntry + 2, state_match);
 
11634
  if (cp != NULL)
 
11635
  {
 
11636
    len_state = StringLen (state_match);
 
11637
    len_qual = StringLen (cntry_str);
 
11638
    
 
11639
    if (cp == cntry_str + len_cntry + 2)
 
11640
    {
 
11641
      /* state is at beginning of string */
 
11642
      len_after = len_qual - len_cntry - 2 - len_state;
 
11643
      if (len_after == 0 || cntry_str [len_cntry + 2 + len_state] == ',')
 
11644
      {
 
11645
        /* already in correct format, nothing after state name */
 
11646
        /* just copy in state name, in case we are correcting case */
 
11647
        StringNCpy (cp, state_match, len_state);
 
11648
        return cntry_str;
 
11649
      }
 
11650
      else
 
11651
      {
 
11652
        /* insert comma */
 
11653
        newname = (CharPtr) MemNew (StringLen (cntry_str) + 3);
 
11654
        StringNCpy (newname, cntry_str, len_cntry + 2 + len_state);
 
11655
        newname [len_cntry + 2 + len_state] = 0;
 
11656
        StringCat (newname, ",");
 
11657
        StringCat (newname, cntry_str + len_cntry + 2 + len_state);
 
11658
        cntry_str = MemFree (cntry_str);
 
11659
        cntry_str = newname;
 
11660
      }
 
11661
    }
 
11662
    else
 
11663
    {
 
11664
      newname = (CharPtr) MemNew (StringLen (cntry_str) + 3);
 
11665
      StringNCpy (newname, cntry_str, len_cntry + 2);
 
11666
      newname [len_cntry + 2] = 0;
 
11667
      StringCat (newname, state_match);
 
11668
      StringCat (newname, ", ");
 
11669
      len_before = cp - cntry_str - 3 - len_cntry;
 
11670
      StringNCpy (newname + len_cntry + 2 + len_state + 2,
 
11671
                  cntry_str + len_cntry + 2,
 
11672
                  len_before);
 
11673
      newname [len_cntry + 2 + len_state + 2 + len_before] = 0;
 
11674
      StringCat (newname, cp + len_state);
 
11675
      cntry_str = MemFree (cntry_str);
 
11676
      cntry_str = newname;
 
11677
    }
 
11678
  }
 
11679
  return cntry_str;
11097
11680
}
11098
11681
 
11099
11682
static void FindCountryName (SubSourcePtr ssp, CharPtr PNTR country_list)
11100
11683
{
11101
11684
  CharPtr       best_match, state_match;
11102
 
  CharPtr       cp, before, newname;
 
11685
  CharPtr       cp, before, newname, after;
11103
11686
  Int4          len_cntry, len_qual, len_name;
11104
11687
 
11105
11688
  if (ssp == NULL || ssp->subtype != SUBSRC_country || StringHasNoText (ssp->name))
11132
11715
  }
11133
11716
  else if (best_match != NULL)
11134
11717
  {     
11135
 
        cp = StringStr (ssp->name, best_match);
 
11718
        cp = StringISearch (ssp->name, best_match);
11136
11719
        len_cntry = StringLen (best_match);
 
11720
        after = cp + len_cntry;
 
11721
        while (isspace (*after) || ispunct(*after)) 
 
11722
        {
 
11723
          after++;
 
11724
        }
11137
11725
        
11138
11726
    if (cp != NULL && !isalpha ((Int4)(cp [len_cntry])))
11139
11727
    {
11140
11728
      len_qual = StringLen (ssp->name);
11141
11729
        if (cp == ssp->name)
11142
11730
        {
11143
 
        if (len_cntry == len_qual || ssp->name [len_cntry] == ':')
11144
 
          {
11145
 
            /* exact match, don't need to do anything */
11146
 
            return;
11147
 
          }
11148
 
            ssp->name [len_cntry] = ':';
11149
 
        return;
 
11731
          newname = (CharPtr) MemNew (len_cntry + StringLen (after) + 3);
 
11732
          sprintf (newname, "%s: %s", best_match, after);
11150
11733
      }
11151
11734
      else
11152
11735
      {
11153
 
            newname = (CharPtr) MemNew (len_qual + 3);
 
11736
        /* strip spaces and punctuation from before */
11154
11737
        *(cp - 1) = 0;
11155
 
        before = StringSave (ssp->name);
11156
 
        StringNCpy (newname, best_match, len_cntry);
11157
 
        newname [len_cntry] = ':';
11158
 
        newname [len_cntry + 1] = ' ';
11159
 
        StringNCpy (newname + len_cntry + 2, before, StringLen (before));
11160
 
        StringCpy (newname + len_cntry + 2 + StringLen (before), cp + len_cntry);
11161
 
        len_name = StringLen (newname);
11162
 
        while (isspace ((Int4)(newname[len_name - 1])) || ispunct ((Int4)(newname [len_name - 1])))
11163
 
        {
11164
 
          newname [len_name - 1] = 0;
11165
 
            len_name --;
11166
 
                }
11167
 
                before = MemFree (before);
11168
 
                MemFree (ssp->name);
11169
 
                ssp->name = newname;
11170
 
      }
 
11738
        before = cp - 2;
 
11739
        while (before >= ssp->name  
 
11740
               && (isspace (*before) || ispunct (*before)))
 
11741
        {
 
11742
          *before = 0;
 
11743
          before--;
 
11744
        }
 
11745
        before = ssp->name;
 
11746
        while (isspace (*before) || ispunct(*before))
 
11747
        {
 
11748
          before++;
 
11749
        }
 
11750
        
 
11751
        newname = (CharPtr) MemNew (len_cntry + StringLen (before) + StringLen (after) + 4);
 
11752
        sprintf (newname, "%s: %s%s%s", best_match, before,
 
11753
                 StringHasNoText (before) || StringHasNoText(after) ? "" : " ",
 
11754
                 after);
 
11755
      }
 
11756
      if (state_match != NULL)
 
11757
      {
 
11758
        newname = MoveStateAndAddComma (newname, state_match, len_cntry);          
 
11759
      }
 
11760
        
 
11761
      /* remove trailing spaces and punctuation */
 
11762
      len_name = StringLen (newname);        
 
11763
      while (isspace ((Int4)(newname[len_name - 1])) || ispunct ((Int4)(newname [len_name - 1])))
 
11764
      {
 
11765
          newname [len_name - 1] = 0;
 
11766
            len_name --;
 
11767
                }                                       
 
11768
          MemFree (ssp->name);
 
11769
          ssp->name = newname;
11171
11770
        }
11172
11771
  }    
11173
11772
}
11187
11786
        if (ssp->subtype != SUBSRC_country || ssp->name == NULL) continue;
11188
11787
    FixCountryNames (ssp);      
11189
11788
        FindCountryName (ssp, list);
11190
 
 
 
11789
  }
 
11790
}
 
11791
 
 
11792
 
 
11793
static void CapitalizeFirstLetterOfEveryWord (CharPtr pString)
 
11794
{
 
11795
  CharPtr pCh;
 
11796
 
 
11797
  pCh = pString;
 
11798
  if (pCh == NULL) return;
 
11799
  if (*pCh == '\0') return;
 
11800
  
 
11801
  while (*pCh != 0)
 
11802
  {
 
11803
    /* skip over spaces */
 
11804
    while (isspace(*pCh))
 
11805
    {
 
11806
      pCh++;
 
11807
    }
 
11808
  
 
11809
    /* capitalize first letter after white space */
 
11810
    if (isalpha (*pCh))
 
11811
    {
 
11812
      *pCh = toupper (*pCh);
 
11813
    }
 
11814
    /* skip over rest of word */
 
11815
    while (*pCh != 0 && !isspace (*pCh))
 
11816
    {
 
11817
      pCh++;
 
11818
    }
 
11819
  }
 
11820
}
 
11821
 
 
11822
 
 
11823
static void CountryCapitalizationFixup (BioSourcePtr biop, Pointer userdata)
 
11824
{
 
11825
  SubSourcePtr  ssp;
 
11826
  CharPtr       cp;
 
11827
 
 
11828
  if (biop == NULL)
 
11829
  {
 
11830
        return;
 
11831
  }
 
11832
 
 
11833
  for (ssp = biop->subtype; ssp != NULL; ssp = ssp->next) 
 
11834
  {
 
11835
        if (ssp->subtype != SUBSRC_country || ssp->name == NULL) continue;
 
11836
    cp = StringChr (ssp->name, ':');
 
11837
        if (cp != NULL)
 
11838
        {
 
11839
          /* skip colon */
 
11840
          cp++;
 
11841
          /* skip over space after colon */
 
11842
          cp += StringSpn (cp, " \t");
 
11843
          
 
11844
          /* reset capitalization */
 
11845
          CapitalizeFirstLetterOfEveryWord (cp);
 
11846
        }
11191
11847
  }  
 
11848
 
11192
11849
}
11193
11850
 
11194
 
extern void CountryLookup (IteM i)
 
11851
static void CountryLookup (IteM i, Boolean with_cap_fix)
11195
11852
{
11196
11853
  BaseFormPtr  bfp;
11197
11854
  SeqEntryPtr  sep;
11210
11867
  list = GetValidCountryList ();
11211
11868
  if (list == NULL) return;
11212
11869
  VisitBioSourcesInSep (sep, list, CountryLookupProc);
 
11870
  if (with_cap_fix)
 
11871
  {
 
11872
    VisitBioSourcesInSep (sep, NULL, CountryCapitalizationFixup);
 
11873
  }
11213
11874
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
11214
11875
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
11215
11876
}
11216
11877
 
 
11878
 
 
11879
extern void CountryLookupWithoutCapFix (IteM i)
 
11880
{
 
11881
  CountryLookup (i, FALSE);
 
11882
}
 
11883
 
 
11884
 
 
11885
extern void CountryLookupWithCapFix (IteM i)
 
11886
{
 
11887
  CountryLookup (i, TRUE);
 
11888
}
 
11889
 
 
11890
 
11217
11891
static Int4 ExtractNumber (CharPtr str)
11218
11892
{
11219
11893
  Int4    j;
11512
12186
    return FALSE;
11513
12187
  }
11514
12188
  
11515
 
  if (StringNCmp (biop->org->taxname, desired_name, desired_len) != 0)
 
12189
  if (StringNICmp (biop->org->taxname, desired_name, desired_len) != 0)
11516
12190
  {
11517
12191
    return FALSE;
11518
12192
  }
11747
12421
 
11748
12422
  
11749
12423
  if (biop == NULL || biop->org == NULL || biop->org->orgname == NULL
11750
 
      || StringNCmp (biop->org->taxname, desired_name, desired_len) != 0) 
 
12424
      || StringNICmp (biop->org->taxname, desired_name, desired_len) != 0) 
11751
12425
  {
11752
12426
    return;
11753
12427
  }
11780
12454
  sprintf (strain_serotype_str, "%s (%s(%s))", biop->org->taxname, 
11781
12455
           strain_str, serotype_str);
11782
12456
  SetTaxNameAndRemoveTaxRef (biop->org, strain_serotype_str);
 
12457
  RemoveOldName(biop->org);
11783
12458
}
11784
12459
 
11785
12460
extern void AddStrainAndSerotypeToInfluenzaAVirusNames (IteM i)
11802
12477
  Update ();                
11803
12478
}
11804
12479
 
 
12480
 
 
12481
extern CharPtr FixInfluenzaVirusName (CharPtr orig_name)
 
12482
{
 
12483
  CharPtr   desired_name = "Influenza A virus";
 
12484
  Int4      desired_len = StringLen (desired_name);
 
12485
  CharPtr   new_name = NULL, cp, src_cp, dst_cp;
 
12486
  
 
12487
  if (StringHasNoText(orig_name)
 
12488
      || StringNICmp (orig_name, desired_name, desired_len) != 0) 
 
12489
  {
 
12490
    return NULL;
 
12491
  }
 
12492
  
 
12493
  cp = orig_name + desired_len;
 
12494
  if (*cp == 0)
 
12495
  {
 
12496
    return NULL;
 
12497
  }
 
12498
  
 
12499
  /* allow one space and only one space between virus and the strain/serotype */
 
12500
  
 
12501
  if (*cp == '(')
 
12502
  {
 
12503
    new_name = (CharPtr) MemNew (sizeof (Char) * (StringLen (orig_name) + 2));
 
12504
    sprintf (new_name, "%s %s", desired_name, cp);
 
12505
  }
 
12506
  else
 
12507
  {
 
12508
    new_name = StringSave (orig_name);
 
12509
  }
 
12510
  
 
12511
  dst_cp = new_name + desired_len;
 
12512
  
 
12513
  if (*dst_cp != ' ')
 
12514
  {
 
12515
    new_name = MemFree (new_name);
 
12516
    return NULL;
 
12517
  }
 
12518
  
 
12519
  dst_cp++;
 
12520
  
 
12521
  src_cp = dst_cp;
 
12522
  /* skip over spaces */
 
12523
  while (isspace (*src_cp))
 
12524
  {
 
12525
    src_cp++;
 
12526
  }
 
12527
  if (*src_cp != '(')
 
12528
  {
 
12529
    new_name = MemFree (new_name);
 
12530
    return NULL;
 
12531
  }
 
12532
  /* copy first open paren */
 
12533
  *dst_cp = *src_cp;
 
12534
  dst_cp++;
 
12535
  src_cp++;
 
12536
  
 
12537
  /* skip over spaces */
 
12538
  while (*src_cp == ' ' || *src_cp == '\t')
 
12539
  {
 
12540
    src_cp++;
 
12541
  }
 
12542
  /* copy to next open paren */
 
12543
  while (*src_cp != '(' && *src_cp != 0)
 
12544
  {
 
12545
    *dst_cp = *src_cp;
 
12546
    dst_cp++;
 
12547
    src_cp++;
 
12548
  }
 
12549
  if (*src_cp == 0)
 
12550
  {
 
12551
    new_name = MemFree (new_name);
 
12552
    return NULL;
 
12553
  }
 
12554
  /* skip back past spaces */
 
12555
  while (*(dst_cp - 1) == ' ' || *(dst_cp - 1) == '\t')
 
12556
  {
 
12557
    dst_cp --;
 
12558
  }
 
12559
  /* copy to first close paren */
 
12560
  while (*src_cp != ')' && *src_cp != 0)
 
12561
  {
 
12562
    *dst_cp = *src_cp;
 
12563
    dst_cp++;
 
12564
    src_cp++;
 
12565
  }
 
12566
  if (*src_cp == 0)
 
12567
  {
 
12568
    new_name = MemFree (new_name);
 
12569
    return NULL;
 
12570
  }
 
12571
  /* skip back past spaces */
 
12572
  while (*(dst_cp - 1) == ' ' || *(dst_cp - 1) == '\t')
 
12573
  {
 
12574
    dst_cp --;
 
12575
  }
 
12576
  /* copy first close paren */
 
12577
  *dst_cp = *src_cp;
 
12578
  dst_cp++;
 
12579
  src_cp++;
 
12580
    /* skip over spaces */
 
12581
  while (*src_cp == ' ' || *src_cp == '\t')
 
12582
  {
 
12583
    src_cp++;
 
12584
  }
 
12585
  /* copy to second close paren */
 
12586
  while (*src_cp != ')' && *src_cp != 0)
 
12587
  {
 
12588
    *dst_cp = *src_cp;
 
12589
    dst_cp++;
 
12590
    src_cp++;
 
12591
  }
 
12592
  if (*src_cp == 0)
 
12593
  {
 
12594
    new_name = MemFree (new_name);
 
12595
    return NULL;
 
12596
  }
 
12597
  /* skip back past spaces */
 
12598
  while (*(dst_cp - 1) == ' ' || *(dst_cp - 1) == '\t')
 
12599
  {
 
12600
    dst_cp --;
 
12601
  }
 
12602
  /* copy second close paren */
 
12603
  *dst_cp = *src_cp;
 
12604
  dst_cp++;
 
12605
  src_cp++;
 
12606
  while (*src_cp == ' ' || *src_cp == '\t')
 
12607
  {
 
12608
      src_cp++;
 
12609
  }
 
12610
  if (*src_cp != 0)
 
12611
  {
 
12612
    new_name = MemFree (new_name);
 
12613
    return NULL;
 
12614
  }
 
12615
  *dst_cp = 0;
 
12616
  return new_name;
 
12617
}
 
12618
 
 
12619
static void 
 
12620
FixupInfluenzaAVirusNamesCallback 
 
12621
(BioSourcePtr biop,
 
12622
 Pointer userdata)
 
12623
{
 
12624
  CharPtr   new_name;
 
12625
  
 
12626
  if (biop == NULL || biop->org == NULL)
 
12627
  {
 
12628
    return;
 
12629
  }
 
12630
  
 
12631
  new_name = FixInfluenzaVirusName (biop->org->taxname);
 
12632
 
 
12633
  if (new_name != NULL)
 
12634
  {
 
12635
    SetTaxNameAndRemoveTaxRef (biop->org, new_name);
 
12636
    RemoveOldName(biop->org);
 
12637
  }
 
12638
}
 
12639
 
 
12640
 
 
12641
extern void FixupInfluenzaAVirusNames(IteM i)
 
12642
{
 
12643
  BaseFormPtr  bfp;
 
12644
  SeqEntryPtr  sep;
 
12645
 
 
12646
#ifdef WIN_MAC
 
12647
  bfp = currentFormDataPtr;
 
12648
#else
 
12649
  bfp = GetObjectExtra (i);
 
12650
#endif
 
12651
  if (bfp == NULL) return;
 
12652
 
 
12653
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
12654
  if (sep == NULL) return;
 
12655
  VisitBioSourcesInSep (sep, NULL, FixupInfluenzaAVirusNamesCallback);
 
12656
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
12657
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
12658
  Update ();                  
 
12659
}
 
12660
 
11805
12661
/* The following code is used for global publication editing. */
11806
12662
/* This section of code is used to create a Publication Constraint */
11807
12663
 
11897
12753
static void PubFieldChoiceToDialog (DialoG d, Pointer userdata)
11898
12754
{
11899
12755
  PubFieldChoiceDialogPtr dlg;
 
12756
  Int4Ptr                 pFieldChoice;
11900
12757
  Int4                    field_choice;
11901
12758
 
11902
12759
  dlg = (PubFieldChoiceDialogPtr) GetObjectExtra (d);
11912
12769
    return;
11913
12770
  }
11914
12771
  
11915
 
  field_choice = (Int4) userdata;
 
12772
  pFieldChoice = (Int4Ptr) userdata;
 
12773
  field_choice = *pFieldChoice;
11916
12774
  if (field_choice == PUB_FIELD_ANY && ! dlg->allow_any)
11917
12775
  {
11918
12776
    field_choice = PUB_FIELD_TITLE;
11965
12823
static Pointer DialogToPubFieldChoice (DialoG d)
11966
12824
{
11967
12825
  PubFieldChoiceDialogPtr dlg;
11968
 
  Int4                    field_choice = PUB_FIELD_ANY, main_field_choice;
 
12826
  Int4                    main_field_choice;
11969
12827
  UIEnum                  val;
 
12828
  Int4Ptr                 retval;
11970
12829
 
11971
12830
  dlg = (PubFieldChoiceDialogPtr) GetObjectExtra (d);
 
12831
  retval = (Int4Ptr) MemNew (sizeof (Int4));
 
12832
  if (retval == NULL)
 
12833
  {
 
12834
    return NULL;
 
12835
  }
 
12836
  *retval = PUB_FIELD_ANY;
11972
12837
  if (dlg == NULL)
11973
12838
  {
11974
 
    return (Pointer) field_choice;
 
12839
    return retval;
11975
12840
  }
11976
12841
  
11977
12842
  main_field_choice = GetValue (dlg->main_list);
11982
12847
  
11983
12848
  if (main_field_choice == PUB_MAIN_ANY)
11984
12849
  {
11985
 
    field_choice = PUB_FIELD_ANY;
 
12850
    *retval = PUB_FIELD_ANY;
11986
12851
  }
11987
12852
  else if (main_field_choice == PUB_MAIN_TITLE)
11988
12853
  {
11989
 
    field_choice = PUB_FIELD_TITLE;
 
12854
    *retval = PUB_FIELD_TITLE;
11990
12855
  }
11991
12856
  else if (main_field_choice == PUB_MAIN_AUTHOR)
11992
12857
  {
11993
12858
    if (GetEnumPopup (dlg->author_list, edit_pub_author_field_alist, &val))
11994
12859
    {
11995
 
      field_choice = val;
 
12860
      *retval = val;
11996
12861
    }
11997
12862
  }
11998
12863
  else if (main_field_choice == PUB_MAIN_AFFILIATION)
11999
12864
  {
12000
12865
    if (GetEnumPopup (dlg->affiliation_list, edit_pub_affiliation_field_alist, &val))
12001
12866
    {
12002
 
      field_choice = val;
 
12867
      *retval = val;
12003
12868
    }
12004
12869
  }
12005
 
  return (Pointer) field_choice;
 
12870
  return retval;
12006
12871
}
12007
12872
 
12008
12873
static DialoG PubFieldChoiceDialog (GrouP h, Boolean allow_any)
12073
12938
 
12074
12939
static void ResetPubConstraintDialog (PubConstraintDialogPtr pcp)
12075
12940
{
 
12941
  Int4 field_choice = PUB_FIELD_ANY;
 
12942
  
12076
12943
  if (pcp == NULL) return;
12077
12944
  SetTitle (pcp->find_str, "");
12078
12945
  SetStatus (pcp->insensitive_to_case, FALSE);
12079
 
  PointerToDialog (pcp->field_for_find, (Pointer) PUB_FIELD_ANY);
 
12946
  PointerToDialog (pcp->field_for_find, &field_choice);
12080
12947
  SetEnumPopup (pcp->pub_status, pub_stat_alist, PUB_STAT_ANY);
12081
12948
}
12082
12949
 
12098
12965
  {
12099
12966
    SetTitle (dlg->find_str, pcp->find_str);
12100
12967
    SetStatus (dlg->insensitive_to_case, pcp->insensitive_to_case);
12101
 
    PointerToDialog (dlg->field_for_find, (Pointer) pcp->field_for_find);
 
12968
    PointerToDialog (dlg->field_for_find,  &(pcp->field_for_find));
12102
12969
    SetEnumPopup (dlg->pub_status, pub_stat_alist, pcp->pub_status);
12103
12970
  }
12104
12971
}
12109
12976
  PubConstraintDialogPtr dlg;
12110
12977
  PubConstraintPtr       pcp;
12111
12978
  UIEnum                 val;
 
12979
  Int4Ptr                retval;
12112
12980
 
12113
12981
  dlg = (PubConstraintDialogPtr) GetObjectExtra (d);
12114
12982
  if (dlg == NULL)
12120
12988
  {
12121
12989
    pcp->find_str = JustSaveStringFromText (dlg->find_str);
12122
12990
    pcp->insensitive_to_case = GetStatus (dlg->insensitive_to_case);
12123
 
    pcp->field_for_find = (Int4) DialogToPointer (dlg->field_for_find);
 
12991
    retval = DialogToPointer (dlg->field_for_find);
 
12992
    if (retval == NULL)
 
12993
    {
 
12994
      pcp->field_for_find = PUB_FIELD_ANY;
 
12995
    }
 
12996
    else
 
12997
    {
 
12998
      pcp->field_for_find = *retval;
 
12999
      retval = MemFree (retval);
 
13000
    }
12124
13001
    if (GetEnumPopup (dlg->pub_status, pub_stat_alist, &val))
12125
13002
    {
12126
13003
      pcp->pub_status = val;
14751
15628
  EditPubFormPtr     epfp;
14752
15629
  PubPtr             pub;
14753
15630
  AuthListPtr        alp;
 
15631
  Int4Ptr            retval;
14754
15632
  
14755
15633
  epfp = (EditPubFormPtr) GetObjectExtra (b);
14756
15634
  if (epfp == NULL) return;
14763
15641
  switch (epfp->edit_type)
14764
15642
  {
14765
15643
    case PUB_EDIT_TYPE_REPLACE_SINGLE_FIELD:
14766
 
      epfp->field_to_set = (Int4) DialogToPointer (epfp->field_to_set_dlg);
 
15644
      retval = DialogToPointer (epfp->field_to_set_dlg);
 
15645
      if (retval == NULL)
 
15646
      {
 
15647
        return;
 
15648
      }
 
15649
      else
 
15650
      {
 
15651
        epfp->field_to_set = *retval;
 
15652
        retval = MemFree (retval); 
 
15653
      }
14767
15654
  
14768
15655
      epfp->repl_string = SaveStringFromText (epfp->repl_string_txt);
14769
15656
      OperateOnPubByConstraint (sep, epfp, EditPubSingleField);
14931
15818
  Int4              field_to_set = PUB_FIELD_ANY;
14932
15819
  Boolean           selected_pub_found = FALSE;
14933
15820
  CharPtr           cp = NULL;
 
15821
  Int4Ptr           retval;
14934
15822
  
14935
15823
  epfp = (EditPubFormPtr) GetObjectExtra (b);
14936
15824
  if (epfp == NULL) return;
14937
15825
  
14938
 
  field_to_set = (Int4) DialogToPointer (epfp->field_to_set_dlg);
 
15826
  retval = DialogToPointer (epfp->field_to_set_dlg);
 
15827
  if (retval == NULL)
 
15828
  {
 
15829
    return;
 
15830
  }
 
15831
  field_to_set = *retval;
 
15832
  retval = MemFree (retval); 
14939
15833
  if (field_to_set == PUB_FIELD_ANY) return;
14940
15834
 
14941
15835
  ssp  = ObjMgrGetSelected();
15909
16803
  Update (); 
15910
16804
}
15911
16805
 
 
16806
 
 
16807
static void PropagateMasterSourceToSegments (BioseqSetPtr bssp)
 
16808
{
 
16809
  SeqEntryPtr       sep, seg_entry;
 
16810
  SeqDescrPtr       sdp, copy_sdp, sdp_next;
 
16811
  SeqMgrDescContext dcontext;
 
16812
  BioseqSetPtr      parts_set;
 
16813
  BioseqPtr         bsp, part_bsp;
 
16814
  ObjValNodePtr     ovp;
 
16815
  
 
16816
  if (bssp == NULL)
 
16817
  {
 
16818
    return;
 
16819
  }
 
16820
  
 
16821
  if (bssp->_class == BioseqseqSet_class_segset)
 
16822
  {
 
16823
    sep = bssp->seq_set;
 
16824
    /* find master segment */
 
16825
    while (sep != NULL && (!IS_Bioseq (sep) || sep->data.ptrvalue == NULL))
 
16826
    {
 
16827
      sep = sep->next;
 
16828
    }
 
16829
    if (sep != NULL)
 
16830
    {
 
16831
      bsp = (BioseqPtr) sep->data.ptrvalue;
 
16832
      sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &dcontext);
 
16833
      if (sdp != NULL)
 
16834
      {
 
16835
        /* don't want to copy descriptors after Bioseq */
 
16836
        sdp_next = sdp->next;
 
16837
        sdp->next = NULL;
 
16838
        
 
16839
        /* find parts set */
 
16840
        sep = bssp->seq_set;
 
16841
        parts_set = NULL;
 
16842
        while (sep != NULL && parts_set == NULL)
 
16843
        {
 
16844
          if (IS_Bioseq_set (sep) && sep->data.ptrvalue != NULL)
 
16845
          {
 
16846
            parts_set = (BioseqSetPtr) sep->data.ptrvalue;
 
16847
            if (parts_set->_class != BioseqseqSet_class_parts)
 
16848
            {
 
16849
              parts_set = NULL;
 
16850
            }
 
16851
          }
 
16852
          sep = sep->next;
 
16853
        }
 
16854
        if (parts_set != NULL)
 
16855
        {
 
16856
          /* add a copy of the master source to each segment */
 
16857
          for (seg_entry = parts_set->seq_set;
 
16858
               seg_entry != NULL; 
 
16859
               seg_entry = seg_entry->next)
 
16860
          {
 
16861
            if (!IS_Bioseq (seg_entry) || seg_entry->data.ptrvalue == NULL)
 
16862
            {
 
16863
              continue;
 
16864
            }
 
16865
            part_bsp = (BioseqPtr) seg_entry->data.ptrvalue;
 
16866
            copy_sdp = (SeqDescrPtr) AsnIoMemCopy (sdp,
 
16867
                                                   (AsnReadFunc) SeqDescrAsnRead,
 
16868
                                                   (AsnWriteFunc) SeqDescrAsnWrite);
 
16869
            ValNodeLink (&(part_bsp->descr),copy_sdp);
 
16870
          }
 
16871
        }
 
16872
        sdp->next = sdp_next;
 
16873
        /* we want to remove the source descriptor from the master */
 
16874
        if (sdp->extended != 0) {
 
16875
          ovp = (ObjValNodePtr) sdp;
 
16876
          ovp->idx.deleteme = TRUE;
 
16877
        }
 
16878
      }
 
16879
    }
 
16880
  }
 
16881
  else
 
16882
  {
 
16883
    for (sep = bssp->seq_set; sep != NULL; sep = sep->next)
 
16884
    {
 
16885
      if (IS_Bioseq_set (sep))
 
16886
      {
 
16887
        PropagateMasterSourceToSegments (sep->data.ptrvalue);
 
16888
      }
 
16889
    }
 
16890
  }
 
16891
}
 
16892
 
 
16893
 
 
16894
static Int2 LIBCALLBACK CopyMasterSourceToSegments (Pointer data)
 
16895
 
 
16896
{
 
16897
  OMProcControlPtr  ompcp;
 
16898
  SeqEntryPtr       sep = NULL;
 
16899
 
 
16900
  ompcp = (OMProcControlPtr) data;
 
16901
  if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
 
16902
  switch (ompcp->input_itemtype) {
 
16903
    case OBJ_BIOSEQ :
 
16904
      sep = GetTopSeqEntryForEntityID (ompcp->input_entityID);
 
16905
      break;
 
16906
    case OBJ_BIOSEQSET :
 
16907
      sep = SeqMgrGetSeqEntryForData (ompcp->input_data);
 
16908
      break;
 
16909
    case 0 :
 
16910
      return OM_MSG_RET_ERROR;
 
16911
    default :
 
16912
      return OM_MSG_RET_ERROR;
 
16913
  }
 
16914
  if (sep == NULL || !IS_Bioseq_set (sep) || sep->data.ptrvalue == NULL) return OM_MSG_RET_ERROR;
 
16915
  
 
16916
  PropagateMasterSourceToSegments(sep->data.ptrvalue);
 
16917
  
 
16918
  DeleteMarkedObjects (ompcp->input_entityID, 0, NULL);
 
16919
  ObjMgrSetDirtyFlag (ompcp->input_entityID, TRUE);
 
16920
  ObjMgrSendMsg (OM_MSG_UPDATE, ompcp->input_entityID, 0, 0);
 
16921
  return OM_MSG_RET_DONE;
 
16922
}
 
16923