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

« back to all changes in this revision

Viewing changes to sequin/sequin3.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:   1/22/95
31
31
*
32
 
* $Revision: 6.629 $
 
32
* $Revision: 6.678 $
33
33
*
34
34
* File Description: 
35
35
*
71
71
#include <saledit.h>
72
72
#include <alignmgr2.h>
73
73
#include <suggslp.h>
 
74
#include <asn2gnbi.h>
 
75
 
 
76
static void ConvertBadInfProc (SeqFeatPtr sfp, Pointer userdata)
 
77
 
 
78
{
 
79
  GBQualPtr  gbq;
 
80
  size_t     len;
 
81
  CharPtr    ptr, str;
 
82
 
 
83
  if (sfp == NULL) return;
 
84
  for (gbq = sfp->qual; gbq != NULL; gbq = gbq->next) {
 
85
    if (StringICmp (gbq->qual, "inference") != 0) continue;
 
86
    if (ValidateInferenceQualifier (gbq->val, FALSE) != VALID_INFERENCE) {
 
87
      if (StringNICmp (gbq->val, "similar to ", 11) == 0) {
 
88
        ptr = StringChr (gbq->val, ':');
 
89
        if (ptr != NULL) {
 
90
          ptr++;
 
91
          if (StringDoesHaveText (ptr)) {
 
92
            len = StringLen ("similar to ") + StringLen (ptr);
 
93
            str = MemNew (len + 5);
 
94
            if (str != NULL) {
 
95
              StringCpy (str, "similar to ");
 
96
              StringCat (str, ptr);
 
97
              gbq->val = MemFree (gbq->val);
 
98
              gbq->val = StringSave (str);
 
99
              MemFree (str);
 
100
            }
 
101
          }
 
102
        }
 
103
      }
 
104
      gbq->qual = MemFree (gbq->qual);
 
105
      gbq->qual = StringSave ("note");
 
106
    }
 
107
  }
 
108
}
 
109
 
 
110
static void ConvertBadInferenceToNote (IteM i)
 
111
 
 
112
{
 
113
  BaseFormPtr  bfp;
 
114
  SeqEntryPtr  sep;
 
115
 
 
116
#ifdef WIN_MAC
 
117
  bfp = currentFormDataPtr;
 
118
#else
 
119
  bfp = GetObjectExtra (i);
 
120
#endif
 
121
  if (bfp == NULL) return;
 
122
 
 
123
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
124
  
 
125
  VisitFeaturesInSep (sep, NULL, ConvertBadInfProc);
 
126
  
 
127
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
128
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
129
  Update (); 
 
130
}
74
131
 
75
132
typedef struct {
76
133
  Int2    level;
453
510
  if (digits + 1 + len > 16) {
454
511
    prefix += digits + 1 + len - 16;
455
512
  }
 
513
  
456
514
  for (sep = pbssp->seq_set, segment = 1; sep != NULL; sep = sep->next, segment++) {
457
515
    DoFixPartLocus (sep, prefix, segment, digits);
458
516
  }
 
517
  
459
518
  if (sbsp == NULL) return;
460
519
  tsip = NULL;
461
520
  for (sip = sbsp->id; sip != NULL; sip = sip->next) {
471
530
  tsip->name = MemFree (tsip->name);
472
531
  sprintf (str, "SEG_%sS", prefix);
473
532
  tsip->name = StringSave (str);
 
533
  SeqMgrReplaceInBioseqIndex (sbsp);
474
534
}
475
535
 
476
536
static void ForceLocusFixup (IteM i)
528
588
  while (sdp != NULL) {
529
589
    nextsdp = sdp->next;
530
590
    empty = FALSE;
531
 
    if (sdp->choice == Seq_descr_genbank && sdp->data.ptrvalue != NULL) {
 
591
    if (sdp->choice == Seq_descr_genbank && sdp->data.ptrvalue == NULL) {
 
592
      empty = TRUE;
 
593
    } else if (sdp->choice == Seq_descr_genbank && sdp->data.ptrvalue != NULL) {
532
594
      gbp = (GBBlockPtr) sdp->data.ptrvalue;
533
595
      gbp->source = MemFree (gbp->source); /* remove within Sequin */
534
596
      gbp->origin = MemFree (gbp->origin);
711
773
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
712
774
  if (sep == NULL) return;
713
775
 
714
 
  AssignCDSmRNAfeatureIDs (sep);
 
776
  AssignFeatureIDs (sep);
 
777
 
 
778
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
779
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
780
  ObjMgrDeSelect (0, 0, 0, 0, NULL);
 
781
  Update ();
 
782
}
 
783
 
 
784
static void ReassignFeatIDs (IteM i)
 
785
 
 
786
{
 
787
  MsgAnswer    ans;
 
788
  BaseFormPtr  bfp;
 
789
  SeqEntryPtr  sep;
 
790
 
 
791
#ifdef WIN_MAC
 
792
  bfp = currentFormDataPtr;
 
793
#else
 
794
  bfp = GetObjectExtra (i);
 
795
#endif
 
796
  if (bfp == NULL) return;
 
797
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
798
  if (sep == NULL) return;
 
799
 
 
800
  ans = Message (MSG_OKC, "Are you sure you want to reassign feature identifiers?");
 
801
  if (ans == ANS_CANCEL) return;
 
802
 
 
803
  ReassignFeatureIDs (sep);
715
804
 
716
805
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
717
806
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
738
827
  ans = Message (MSG_YN, "Are you sure you want to remove feature IDs and links?");
739
828
  if (ans == ANS_NO) return;
740
829
 
741
 
  ClearCDSmRNAfeatureIDs (sep);
 
830
  ClearFeatureIDs (sep);
742
831
 
743
832
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
744
833
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
841
930
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
842
931
  if (sep == NULL) return;
843
932
 
844
 
  AssignCDSmRNAfeatureIDs (sep);
 
933
  AssignFeatureIDs (sep);
845
934
 
846
935
  ssp = ObjMgrGetSelected ();
847
936
  if (ssp == NULL) {
2961
3050
  Message (MSG_OK, "Some manual desktop manipulations remain");
2962
3051
}
2963
3052
 
 
3053
 
 
3054
static void CollectBioseqsForConversion (BioseqPtr bsp, Pointer userdata)
 
3055
{
 
3056
  ValNodePtr PNTR list;
 
3057
  
 
3058
  if (bsp == NULL || bsp->repr != Seq_repr_raw || ISA_aa (bsp->mol)) return;
 
3059
  if (userdata == NULL)
 
3060
  {
 
3061
    return;
 
3062
  }
 
3063
  list = (ValNodePtr PNTR) userdata;
 
3064
  
 
3065
  ValNodeAddPointer (list, 0, bsp);
 
3066
}
 
3067
 
 
3068
static ValNodePtr GetAnnotListForBspList (ValNodePtr bsp_list)
 
3069
{
 
3070
  BioseqPtr   bsp;
 
3071
  SeqAnnotPtr sanp;
 
3072
  ValNodePtr  complete_annot_list = NULL, align_annot_list;
 
3073
  ValNodePtr  annot_vnp, vnp, bsp_vnp;
 
3074
  Boolean     found;
 
3075
 
 
3076
  for (bsp_vnp = bsp_list; bsp_vnp != NULL; bsp_vnp = bsp_vnp->next)
 
3077
  {
 
3078
    bsp = (BioseqPtr)(bsp_vnp->data.ptrvalue);
 
3079
    align_annot_list = FindAlignSeqAnnotsForBioseq (bsp);
 
3080
    for (annot_vnp = align_annot_list; annot_vnp != NULL; annot_vnp = annot_vnp->next)
 
3081
    {
 
3082
      sanp = (SeqAnnotPtr) annot_vnp->data.ptrvalue;
 
3083
      if (sanp->type == 2 && sanp->data != NULL)
 
3084
      {
 
3085
        for (vnp = complete_annot_list, found = FALSE;
 
3086
             vnp != NULL && !found;
 
3087
             vnp = vnp->next)
 
3088
        {
 
3089
          if (vnp->data.ptrvalue == sanp)
 
3090
          {
 
3091
            found = TRUE;
 
3092
          }
 
3093
        }
 
3094
        if (!found)
 
3095
        {
 
3096
          ValNodeAddPointer (&complete_annot_list, 0, sanp);
 
3097
        }
 
3098
      }
 
3099
    }
 
3100
    align_annot_list = ValNodeFree (align_annot_list);
 
3101
  }
 
3102
  return complete_annot_list;
 
3103
}
 
3104
 
 
3105
 
 
3106
static void 
 
3107
CleanupAlignmentsAfterConversion 
 
3108
(ValNodePtr adjusted_bsp_list,
 
3109
 Uint2 entityID)
 
3110
{
 
3111
  ValNodePtr  align_annot_list, annot_vnp;
 
3112
  SeqAnnotPtr sanp;
 
3113
  
 
3114
  align_annot_list = GetAnnotListForBspList (adjusted_bsp_list);
 
3115
  for (annot_vnp = align_annot_list;
 
3116
       annot_vnp != NULL; 
 
3117
       annot_vnp = annot_vnp->next)
 
3118
  {
 
3119
    sanp = annot_vnp->data.ptrvalue;
 
3120
    if (sanp != NULL && sanp->type == 2)
 
3121
    {
 
3122
      ConsolidateSegmentsOverKnownLengthGaps (sanp->data);
 
3123
      FixOneAlignmentOverGaps (sanp->data, entityID);
 
3124
    }
 
3125
  }
 
3126
  align_annot_list = ValNodeFree (align_annot_list);
 
3127
  DeleteMarkedObjects (entityID, 0, NULL);
 
3128
  
 
3129
}
 
3130
 
 
3131
static void CorrectAlignmentsAfterNToGapConversion (SeqEntryPtr sep, Uint2 entityID)
 
3132
{
 
3133
  ValNodePtr adjusted_bsp_list = NULL;
 
3134
  
 
3135
  VisitBioseqsInSep (sep, &adjusted_bsp_list, CollectBioseqsForConversion);
 
3136
  CleanupAlignmentsAfterConversion (adjusted_bsp_list, entityID);
 
3137
  adjusted_bsp_list = ValNodeFree (adjusted_bsp_list);
 
3138
}
 
3139
 
 
3140
static void ConvertNsToGapsWithSizeList (Uint2 entityID, Int4Ptr gap_sizes, Boolean adjust_cds)
 
3141
{
 
3142
  ValNodePtr  adjusted_bsp_list = NULL;
 
3143
  SeqEntryPtr sep;
 
3144
  
 
3145
  sep = GetTopSeqEntryForEntityID (entityID);
 
3146
  if (sep == NULL) return;
 
3147
  VisitBioseqsInSep (sep, &adjusted_bsp_list, CollectBioseqsForConversion);
 
3148
 
 
3149
  if (adjust_cds)
 
3150
  {
 
3151
    /* remove the gap locations from the coding regions first */
 
3152
    VisitBioseqsInSep (sep, gap_sizes, PrepareCodingRegionLocationsForDeltaConversionCallback);
 
3153
  }
 
3154
  
 
3155
  VisitBioseqsInSep (sep, gap_sizes, ConvertNsToGaps);
 
3156
  CleanupAlignmentsAfterConversion (adjusted_bsp_list, entityID);
 
3157
  adjusted_bsp_list = ValNodeFree (adjusted_bsp_list);
 
3158
  ObjMgrSetDirtyFlag (entityID, TRUE);
 
3159
  ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
3160
}
 
3161
 
 
3162
 
2964
3163
static void RawSeqToDeltaSeq (IteM i)
2965
3164
 
2966
3165
{
2967
3166
  BaseFormPtr  bfp;
2968
 
  SeqEntryPtr  sep;
2969
3167
 
2970
3168
#ifdef WIN_MAC
2971
3169
  bfp = currentFormDataPtr;
2973
3171
  bfp = GetObjectExtra (i);
2974
3172
#endif
2975
3173
  if (bfp == NULL) return;
2976
 
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2977
 
  if (sep == NULL) return;
2978
 
  VisitBioseqsInSep (sep, NULL, ConvertNsToGaps);
2979
 
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2980
 
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
3174
  ConvertNsToGapsWithSizeList (bfp->input_entityID, NULL, FALSE);
2981
3175
}
2982
3176
 
2983
3177
static void RawSeqToDeltaSeqUnknownLengthGaps (IteM i)
2984
3178
 
2985
3179
{
2986
3180
  BaseFormPtr  bfp;
2987
 
  SeqEntryPtr  sep;
2988
3181
  Int4         gap_sizes[2];
2989
3182
 
2990
3183
#ifdef WIN_MAC
2993
3186
  bfp = GetObjectExtra (i);
2994
3187
#endif
2995
3188
  if (bfp == NULL) return;
2996
 
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2997
 
  if (sep == NULL) return;
2998
3189
  gap_sizes [0] = 100;
2999
3190
  gap_sizes [1] = -1;
3000
 
  VisitBioseqsInSep (sep, gap_sizes, ConvertNsToGaps);
3001
 
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3002
 
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
3191
  ConvertNsToGapsWithSizeList (bfp->input_entityID, gap_sizes, FALSE);
3003
3192
}
3004
3193
 
3005
3194
static void RawSeqToDeltaSeqUnknown100LengthGaps (IteM i)
3006
3195
 
3007
3196
{
3008
3197
  BaseFormPtr  bfp;
3009
 
  SeqEntryPtr  sep;
3010
3198
  Int4         gap_sizes[2];
3011
3199
 
3012
3200
#ifdef WIN_MAC
3015
3203
  bfp = GetObjectExtra (i);
3016
3204
#endif
3017
3205
  if (bfp == NULL) return;
3018
 
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
3019
 
  if (sep == NULL) return;
3020
3206
  gap_sizes [0] = -1;
3021
3207
  gap_sizes [1] = 0;
3022
 
  VisitBioseqsInSep (sep, gap_sizes, ConvertNsToGaps);
3023
 
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
3024
 
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
3208
  ConvertNsToGapsWithSizeList (bfp->input_entityID, gap_sizes, FALSE);
3025
3209
}
3026
3210
 
3027
3211
#if 0
3333
3517
  
3334
3518
  
3335
3519
  Hide (gcp->form);
3336
 
  if (GetStatus (gcp->adjust_CDS_locations))
3337
 
  {
3338
 
    /* remove the gap locations from the coding regions first */
3339
 
    VisitBioseqsInSep (sep, gap_sizes, PrepareCodingRegionLocationsForDeltaConversionCallback);
3340
 
    /* then change the gap locations into delta gaps */
3341
 
    VisitBioseqsInSep (sep, gap_sizes, ConvertNsToGaps); 
3342
 
  }
3343
 
  ObjMgrSetDirtyFlag (gcp->input_entityID, TRUE);
3344
 
  ObjMgrSendMsg (OM_MSG_UPDATE, gcp->input_entityID, 0, 0);
 
3520
  ConvertNsToGapsWithSizeList (gcp->input_entityID, gap_sizes, GetStatus (gcp->adjust_CDS_locations));
 
3521
 
3345
3522
  Remove (gcp->form);  
3346
3523
}
3347
3524
 
3376
3553
  {
3377
3554
        msg = CreateListMessage ("Sequence", 
3378
3555
                                 raw_in_aln->next == NULL 
3379
 
                                      ? " is in an alignment.  Do you want to continue?" 
3380
 
                                      : " are in alignments.  Do you want to continue?",
 
3556
                                      ? " is in an alignment.  The alignment will be automatically adjusted after conversion.  Do you want to continue?" 
 
3557
                                      : " are in alignments.  The alignment will be automatically adjusted after conversion.  Do you want to continue?",
3381
3558
                                      raw_in_aln);
3382
3559
        raw_in_aln = ValNodeFreeData (raw_in_aln);
3383
3560
    ans = Message (MSG_YN, msg);
3548
3725
  
3549
3726
} DeltaConversionData, PNTR DeltaConversionPtr;
3550
3727
 
 
3728
 
 
3729
static SeqAlignPtr 
 
3730
AdjustOneAlignmentForOneBioseqBasedOnGapLocations 
 
3731
(SeqAlignPtr salp_to_adjust,
 
3732
 BioseqPtr   bsp,
 
3733
 ValNodePtr  gaps,
 
3734
 SeqAlignPtr gap_salp)
 
3735
{
 
3736
  Int4          aln_index;
 
3737
  SeqIdPtr      sip;
 
3738
  ValNodePtr    gap_vnp;
 
3739
  GapLocInfoPtr glip;
 
3740
  SeqLocPtr     slp;
 
3741
  Int4          gap_start;
 
3742
  Int4          cumulative_offset = 0;
 
3743
  DenseSegPtr   dsp;
 
3744
  
 
3745
  if (salp_to_adjust == NULL || salp_to_adjust->segtype != SAS_DENSEG
 
3746
      || bsp == NULL || gaps == NULL)
 
3747
  {
 
3748
    return salp_to_adjust;
 
3749
  }
 
3750
 
 
3751
  dsp = (DenseSegPtr) salp_to_adjust->segs;
 
3752
  if (dsp == NULL) {
 
3753
     return salp_to_adjust;
 
3754
  }
 
3755
  sip = bsp->id;
 
3756
  aln_index = 0;
 
3757
  while (sip != NULL && aln_index == 0)
 
3758
  {
 
3759
    aln_index = SeqIdOrderInBioseqIdList (sip, dsp->ids);
 
3760
    if (aln_index == 0)
 
3761
    {
 
3762
      sip = sip->next;
 
3763
    }
 
3764
  }
 
3765
  if (aln_index == 0) {
 
3766
     /* bioseq not in alignment */
 
3767
     return salp_to_adjust;
 
3768
  }
 
3769
  
 
3770
  for (gap_vnp = gaps; gap_vnp != NULL; gap_vnp = gap_vnp->next)
 
3771
  {
 
3772
    glip = (GapLocInfoPtr) gap_vnp->data.ptrvalue;
 
3773
    if (glip == NULL || glip->replace)
 
3774
    {
 
3775
      continue;
 
3776
    }
 
3777
    gap_start = glip->start_pos;
 
3778
    if (gap_salp != NULL)
 
3779
    {
 
3780
      gap_start = AlnMgr2MapSeqAlignToBioseq(gap_salp, gap_start, aln_index);
 
3781
    }
 
3782
    if (gap_start < 1)
 
3783
    {
 
3784
      continue;
 
3785
    }
 
3786
    gap_start += cumulative_offset;
 
3787
    if (gap_start > bsp->length)
 
3788
    {
 
3789
      continue;
 
3790
    }
 
3791
    slp = SeqLocIntNew (gap_start, gap_start + glip->length - 1, Seq_strand_plus, sip);
 
3792
    salp_to_adjust = SeqAlignInsertByLoc (slp, salp_to_adjust);
 
3793
    cumulative_offset += glip->length;
 
3794
  }
 
3795
  
 
3796
  return salp_to_adjust;
 
3797
}
 
3798
 
 
3799
 
 
3800
static void ShiftAlignmentForGapLocations (SeqAnnotPtr sanp, ValNodePtr gaps)
 
3801
{
 
3802
  SeqAlignPtr   salp;
 
3803
  DenseSegPtr   dsp;
 
3804
  Int4          alignment_position = 0, k;
 
3805
  Int4          cumulative_offset = 0;
 
3806
  BoolPtr       shift_this_row;
 
3807
  Int4          seg_num = 0, shift_seg;
 
3808
  ValNodePtr    gap_vnp;
 
3809
  GapLocInfoPtr glip;
 
3810
  
 
3811
  if (sanp == NULL || sanp->data == NULL || sanp->type != 2 || gaps == NULL)
 
3812
  {
 
3813
    return;
 
3814
  }
 
3815
  
 
3816
  salp = (SeqAlignPtr) sanp->data;
 
3817
  if (salp->segtype != SAS_DENSEG || salp->segs == NULL)
 
3818
  {
 
3819
    return;
 
3820
  }
 
3821
  
 
3822
  dsp = (DenseSegPtr) salp->segs;
 
3823
  
 
3824
  shift_this_row = (BoolPtr) MemNew (sizeof (Boolean) * dsp->dim);
 
3825
  
 
3826
  for (gap_vnp = gaps; gap_vnp != NULL; gap_vnp = gap_vnp->next)
 
3827
  {
 
3828
    glip = (GapLocInfoPtr) gap_vnp->data.ptrvalue;
 
3829
    if (glip == NULL || glip->replace)
 
3830
    {
 
3831
      continue;
 
3832
    }
 
3833
    while (seg_num < dsp->numseg 
 
3834
           && alignment_position + dsp->lens [seg_num] < glip->start_pos + cumulative_offset)
 
3835
           
 
3836
    {
 
3837
      alignment_position += dsp->lens [seg_num];
 
3838
      seg_num++;
 
3839
    }
 
3840
 
 
3841
    if (seg_num < dsp->numseg)
 
3842
    {
 
3843
      dsp->lens [seg_num] += glip->length;
 
3844
      for (k = 0; k < dsp->dim; k++)
 
3845
      {
 
3846
        if (dsp->starts [seg_num * dsp->dim + k] == -1)
 
3847
        {
 
3848
          shift_this_row[k] = FALSE;
 
3849
        }
 
3850
        else
 
3851
        {
 
3852
          shift_this_row[k] = TRUE;
 
3853
        }
 
3854
      }
 
3855
      
 
3856
      /* shift the rows for which a gap was inserted */
 
3857
      for (k = 0; k < dsp->dim; k++)
 
3858
      {
 
3859
        if (!shift_this_row[k])
 
3860
        {
 
3861
          continue;
 
3862
        }
 
3863
        /* shift start for minus strand rows for seg_num only */
 
3864
        if (dsp->strands != NULL 
 
3865
            && dsp->strands [seg_num * dsp->dim + k] == Seq_strand_minus
 
3866
            && dsp->starts [seg_num * dsp->dim + k] != -1)
 
3867
        {
 
3868
          dsp->starts [seg_num * dsp->dim + k] -= glip->length;
 
3869
        }
 
3870
        /* shift starts for rows after seg_num */
 
3871
        for (shift_seg = seg_num + 1;
 
3872
             shift_seg < dsp->numseg;
 
3873
             shift_seg++)
 
3874
        {
 
3875
          if (dsp->starts [shift_seg * dsp->dim + k] != -1)
 
3876
          {
 
3877
            if (dsp->strands == NULL
 
3878
                || dsp->strands [shift_seg * dsp->dim + k] != Seq_strand_minus)
 
3879
            {
 
3880
              dsp->starts [shift_seg * dsp->dim + k] += glip->length;
 
3881
            }
 
3882
            else
 
3883
            {
 
3884
              dsp->starts [shift_seg * dsp->dim + k] -= glip->length;
 
3885
            }
 
3886
          }
 
3887
        }
 
3888
      }
 
3889
    }
 
3890
    cumulative_offset += glip->length;
 
3891
  }  
 
3892
  shift_this_row = MemFree (shift_this_row);
 
3893
}
 
3894
 
 
3895
static void 
 
3896
AdjustAlignmentsBasedOnGapLocations 
 
3897
(ValNodePtr  adjusted_bsp_list,
 
3898
 ValNodePtr  gaps,
 
3899
 SeqAlignPtr salp,
 
3900
 Uint2       entityID)
 
3901
{
 
3902
  ValNodePtr  align_annot_list, annot_vnp, bsp_vnp;
 
3903
  SeqAnnotPtr sanp, adjustment_sanp = NULL;
 
3904
  BioseqPtr   bsp;
 
3905
  Int4        cumulative_offset = 0;
 
3906
  
 
3907
  for (bsp_vnp = adjusted_bsp_list; bsp_vnp != NULL; bsp_vnp = bsp_vnp->next)
 
3908
  {
 
3909
    bsp = (BioseqPtr)(bsp_vnp->data.ptrvalue);
 
3910
    align_annot_list = FindAlignSeqAnnotsForBioseq (bsp);
 
3911
    for (annot_vnp = align_annot_list;
 
3912
         annot_vnp != NULL; 
 
3913
         annot_vnp = annot_vnp->next)
 
3914
    {
 
3915
      sanp = annot_vnp->data.ptrvalue;
 
3916
      if (sanp != NULL && sanp->type == 2)
 
3917
      {
 
3918
        if (sanp->data == salp)
 
3919
        {
 
3920
          adjustment_sanp = sanp;
 
3921
        }
 
3922
        else
 
3923
        {
 
3924
          sanp->data = AdjustOneAlignmentForOneBioseqBasedOnGapLocations 
 
3925
                              (sanp->data, bsp, gaps, salp);
 
3926
        }
 
3927
      }
 
3928
    }
 
3929
    align_annot_list = ValNodeFree (align_annot_list);
 
3930
  }
 
3931
 
 
3932
  if (adjustment_sanp != NULL)
 
3933
  {
 
3934
    ShiftAlignmentForGapLocations (adjustment_sanp, gaps);
 
3935
  }
 
3936
    
 
3937
  CleanupAlignmentsAfterConversion (adjusted_bsp_list, entityID);
 
3938
}
 
3939
 
 
3940
 
3551
3941
static void 
3552
3942
ConvertRawBioseqToDelta 
3553
3943
(BioseqPtr bsp,
3695
4085
  sep = GetTopSeqEntryForEntityID (bsp->idx.entityID);
3696
4086
 
3697
4087
  VisitFeaturesInSep (sep, bsp, AdjustCDSLocationsForGapsCallback);
 
4088
  
3698
4089
}
3699
4090
 
 
4091
typedef struct converttodelta 
 
4092
{
 
4093
  ValNodePtr  location_list;
 
4094
  ValNodePtr  affected_bioseq_list;
 
4095
  SeqAlignPtr salp;
 
4096
} ConvertToDeltaData, PNTR ConvertToDeltaPtr;
 
4097
 
3700
4098
static void ConvertBioseqToDeltaWithSequenceGapList (BioseqPtr bsp, Pointer userdata)
3701
4099
{
3702
 
  ConvertRawBioseqToDelta (bsp, userdata, NULL, -1);
 
4100
  ConvertToDeltaPtr ctdp;
 
4101
  
 
4102
  if (bsp == NULL || bsp->id == NULL 
 
4103
      || bsp->repr != Seq_repr_raw || ISA_aa (bsp->mol)
 
4104
      || userdata == NULL)
 
4105
  {
 
4106
    return;
 
4107
  }
 
4108
  ctdp = (ConvertToDeltaPtr) userdata;
 
4109
  if (ctdp->location_list == NULL)
 
4110
  {
 
4111
    return;
 
4112
  }
 
4113
  ValNodeAddPointer (&(ctdp->affected_bioseq_list), 0, bsp);
 
4114
  ConvertRawBioseqToDelta (bsp, ctdp->location_list, NULL, -1);
3703
4115
}
3704
4116
 
3705
4117
static void ConvertBioseqToDeltaWithAlignmentGapList (BioseqPtr bsp, Pointer userdata)
3706
4118
{
3707
 
  Int4        aln_row = -1;
3708
 
  SeqIdPtr    sip, sip_next;
3709
 
  SeqAlignPtr salp;
3710
 
  
3711
 
  if (bsp == NULL || bsp->id == NULL || userdata == NULL)
3712
 
  {
3713
 
    return;
3714
 
  }
3715
 
  salp = FindAlignmentsForBioseq (bsp);
 
4119
  Int4              aln_row = -1;
 
4120
  SeqIdPtr          sip, sip_next;
 
4121
  SeqAlignPtr       salp;
 
4122
  ConvertToDeltaPtr ctdp;
 
4123
  ValNodePtr        annot_list;
 
4124
  SeqAnnotPtr       sanp;
 
4125
  
 
4126
  if (bsp == NULL || bsp->id == NULL 
 
4127
      || bsp->repr != Seq_repr_raw || ISA_aa (bsp->mol)
 
4128
      || userdata == NULL)
 
4129
  {
 
4130
    return;
 
4131
  }
 
4132
  ctdp = (ConvertToDeltaPtr) userdata;
 
4133
  if (ctdp->location_list == NULL)
 
4134
  {
 
4135
    return;
 
4136
  }
 
4137
  
 
4138
  annot_list = FindAlignSeqAnnotsForBioseq (bsp);
 
4139
  if (annot_list == NULL || annot_list->data.ptrvalue == NULL)
 
4140
  {
 
4141
    return;
 
4142
  }
 
4143
  sanp = (SeqAnnotPtr) annot_list->data.ptrvalue;
 
4144
  if (sanp->type != 2 || sanp->data == NULL)
 
4145
  {
 
4146
    return;
 
4147
  }
3716
4148
 
3717
 
  if (salp == NULL)
3718
 
  {
3719
 
    return;
3720
 
  }
 
4149
  salp = sanp->data;
 
4150
  ctdp->salp = salp;
 
4151
  
 
4152
  /* Make sure alignment is indexed.
 
4153
   */
 
4154
  AlnMgr2IndexSeqAlignEx(salp, FALSE);
3721
4155
  
3722
4156
  sip = bsp->id;
3723
4157
  
3730
4164
    sip = sip_next;
3731
4165
  }
3732
4166
 
3733
 
  ConvertRawBioseqToDelta (bsp, userdata, salp, aln_row);
 
4167
  ValNodeAddPointer (&(ctdp->affected_bioseq_list), 0, bsp);
 
4168
  ConvertRawBioseqToDelta (bsp, ctdp->location_list, salp, aln_row);
3734
4169
}
3735
4170
 
3736
4171
static int LIBCALLBACK SortGapLocations (VoidPtr ptr1, VoidPtr ptr2)
3848
4283
static void DoConvertRawToDeltaWithGapLocations (ButtoN b)
3849
4284
{
3850
4285
  DeltaConversionPtr dcp;
3851
 
  ValNodePtr         location_list;
3852
4286
  SeqEntryPtr        sep;
 
4287
  ConvertToDeltaData ctdd;
3853
4288
 
3854
4289
  dcp = (DeltaConversionPtr) GetObjectExtra (b);
3855
4290
  if (dcp == NULL)
3863
4298
    return;
3864
4299
  }
3865
4300
 
3866
 
  location_list = DialogToPointer (dcp->gap_locations);
3867
 
  if (location_list == NULL)
 
4301
  ctdd.location_list = DialogToPointer (dcp->gap_locations);
 
4302
  if (ctdd.location_list == NULL)
3868
4303
  {
3869
4304
    Message (MSG_ERROR, "Must supply valid gap locations!");
3870
4305
    return;
3871
4306
  }
 
4307
  ctdd.affected_bioseq_list = NULL;
 
4308
  ctdd.salp = NULL;
3872
4309
  
3873
4310
  Hide (dcp->form);
3874
4311
  WatchCursor ();
3875
4312
  Update (); 
3876
4313
  if (dcp->coord_grp == NULL || GetValue (dcp->coord_grp) == 1)
3877
4314
  {
3878
 
    VisitBioseqsInSep (sep, location_list, ConvertBioseqToDeltaWithSequenceGapList);
 
4315
    VisitBioseqsInSep (sep, &ctdd, ConvertBioseqToDeltaWithSequenceGapList);
3879
4316
  }
3880
4317
  else
3881
4318
  {
3882
 
    VisitBioseqsInSep (sep, location_list, ConvertBioseqToDeltaWithAlignmentGapList);
 
4319
    VisitBioseqsInSep (sep, &ctdd, ConvertBioseqToDeltaWithAlignmentGapList);
3883
4320
  }
3884
 
  location_list = ValNodeFreeData (location_list);
 
4321
  
 
4322
  AdjustAlignmentsBasedOnGapLocations (ctdd.affected_bioseq_list, 
 
4323
                                       ctdd.location_list, ctdd.salp, 
 
4324
                                       dcp->input_entityID);                                      
 
4325
 
 
4326
  ctdd.affected_bioseq_list = ValNodeFree (ctdd.affected_bioseq_list);
 
4327
  ctdd.location_list = ValNodeFreeData (ctdd.location_list);
3885
4328
  
3886
4329
  if (GetStatus (dcp->adjust_CDS_locations))
3887
4330
  {
3888
4331
    VisitFeaturesInSep (sep, NULL, AdjustCDSLocationsForGapsCallback);
3889
4332
  }
3890
4333
  
 
4334
  
3891
4335
  ObjMgrSetDirtyFlag (dcp->input_entityID, TRUE);
3892
4336
  ObjMgrSendMsg (OM_MSG_UPDATE, dcp->input_entityID, 0, 0);
3893
4337
  Remove (dcp->form);    
4735
5179
  fsp = DialogToPointer (fgp->filter_grp);
4736
5180
  
4737
5181
  sep = GetTopSeqEntryForEntityID (fgp->input_entityID);
4738
 
  if (sep == NULL) return;
 
5182
  if (sep == NULL) return FALSE;
4739
5183
  fgp->single_interval = GetStatus (fgp->single_interval_btn);
4740
5184
  if (GetStatus (fgp->selected_features_only_btn))
4741
5185
  {
4955
5399
  ChangeGeneFeatureSelection (fgp);
4956
5400
}
4957
5401
 
4958
 
typedef struct genetocdsform
4959
 
{
4960
 
  FEATURE_FORM_BLOCK
4961
 
 
4962
 
  PopuP   gene_qual_popup;
4963
 
  PopuP   gene_qual_popup2;
4964
 
  PopuP   gene_qual_popup3;
4965
 
  GrouP   qual_caps_grp;
4966
 
  TexT    append_text;
4967
 
  ButtoN  remove_qual_btn1;
4968
 
  ButtoN  remove_qual_btn2;
4969
 
  ButtoN  remove_qual_btn3;
4970
 
  ButtoN  accept_btn;
4971
 
  
4972
 
  Int4    gene_qual_choice;
4973
 
  Int4    gene_qual_choice2;
4974
 
  Int4    gene_qual_choice3;
4975
 
  CharPtr append_string;
4976
 
  Int4    caps_choice;
4977
 
  Boolean remove_gene_qual1;
4978
 
  Boolean remove_gene_qual2;
4979
 
  Boolean remove_gene_qual3;
4980
 
  SeqEntryPtr sep;
4981
 
  FILE    *log_fp;
4982
 
  Boolean data_in_log;
4983
 
  
4984
 
} GeneToCDSFormData, PNTR GeneToCDSFormPtr;
4985
 
 
4986
 
static CharPtr GetQualStringForQualChoice (GeneRefPtr grp, SeqFeatPtr sfp, Int4 choice)
4987
 
{
4988
 
  CharPtr str = NULL;
4989
 
  switch (choice)
4990
 
  {
4991
 
        case 2:
4992
 
          str = grp->locus;
4993
 
          break;
4994
 
        case 3:
4995
 
          str =  grp->desc;
4996
 
          break;
4997
 
        case 4:
4998
 
          str =  sfp->comment;
4999
 
          break;
5000
 
  }
5001
 
  return str;
5002
 
}
5003
 
 
5004
 
static Int4 GetGeneQualChoice (GeneToCDSFormPtr gcfp, SeqFeatPtr sfp, GeneRefPtr grp)
5005
 
{
5006
 
  if (gcfp == NULL) return 0;
5007
 
  
5008
 
  if (gcfp->gene_qual_choice != 1 
5009
 
    && StringHasNoText (GetQualStringForQualChoice (grp, sfp, gcfp->gene_qual_choice)))
5010
 
  {
5011
 
    if (gcfp->gene_qual_choice2 != 1 
5012
 
      && StringHasNoText (GetQualStringForQualChoice (grp, sfp, gcfp->gene_qual_choice2)))
5013
 
    {
5014
 
      return gcfp->gene_qual_choice3;
5015
 
    }
5016
 
    else
5017
 
    {
5018
 
      return gcfp->gene_qual_choice2;           
5019
 
    }
5020
 
  }
5021
 
  else
5022
 
  {
5023
 
        return gcfp->gene_qual_choice;
5024
 
  }
5025
 
}
5026
 
 
5027
 
static void LogGeneToCDSNoProtein (GeneToCDSFormPtr gcfp, CharPtr gene_label, SeqIdPtr sip)
5028
 
{
5029
 
  Char       id [41];
5030
 
 
5031
 
  if (gcfp == NULL || gcfp->log_fp == NULL || sip == NULL) return;
5032
 
 
5033
 
  id [0] = '\0';
5034
 
  SeqIdWrite (SeqIdFindBest (sip, 0), id, PRINTID_FASTA_LONG, sizeof (id) - 1);
5035
 
  
5036
 
  if (StringHasNoText (gene_label))
5037
 
  {
5038
 
    fprintf (gcfp->log_fp, "No protein added for unlabeled gene on sequence %s\n", id);
5039
 
  }
5040
 
  else
5041
 
  {
5042
 
    fprintf (gcfp->log_fp, "No protein added for %s on sequence %s\n", gene_label, id);
5043
 
  }
5044
 
  gcfp->data_in_log = TRUE;
5045
 
}
5046
 
 
5047
 
static void GeneToCDSCallback (SeqFeatPtr sfp, Pointer userdata)
5048
 
 
5049
 
{
5050
 
  SeqFeatPtr        cds;
5051
 
  GeneRefPtr        grp;
5052
 
  SeqMgrFeatContext context;
5053
 
  Int2              genCode;
5054
 
  CdRegionPtr       crp;
5055
 
  ByteStorePtr      bs;
5056
 
  BioseqPtr         bsp;
5057
 
  SeqEntryPtr       psep, nsep, old, topsep;
5058
 
  MolInfoPtr        mip;
5059
 
  ProtRefPtr        prp;
5060
 
  Char              ch;
5061
 
  ValNodePtr        descr;
5062
 
  Int2              i;
5063
 
  Boolean           partial5, partial3;
5064
 
  CharPtr           prot;
5065
 
  CharPtr           ptr;
5066
 
  ValNodePtr        vnp;
5067
 
  CharPtr           protName = NULL;
5068
 
  GeneToCDSFormPtr  gcfp;
5069
 
  Int4              prot_len;
5070
 
  CharPtr           cp;
5071
 
  Int4              gene_qual_choice;
5072
 
  CharPtr           qual_val = NULL;
5073
 
  
5074
 
  if (sfp == NULL || sfp->data.choice != SEQFEAT_GENE || userdata == NULL)
5075
 
        return;
5076
 
 
5077
 
  gcfp = (GeneToCDSFormPtr) userdata;
5078
 
 
5079
 
  CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
5080
 
 
5081
 
  cds = SeqMgrGetOverlappingCDS (sfp->location, &context);
5082
 
  if (cds != NULL) 
5083
 
  {
5084
 
    return;     
5085
 
  }
5086
 
 
5087
 
  if (SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL,
5088
 
                               0, 0, sfp, &context) == NULL) return;
5089
 
 
5090
 
  grp = (GeneRefPtr) sfp->data.value.ptrvalue;
5091
 
  
5092
 
  /* use the controls to determine the protein name */
5093
 
  prot_len = 0;
5094
 
  
5095
 
  gene_qual_choice = GetGeneQualChoice (gcfp, sfp, grp);
5096
 
  qual_val = GetQualStringForQualChoice (grp, sfp, gene_qual_choice);
5097
 
 
5098
 
  
5099
 
  if (gene_qual_choice == 1)
5100
 
  {
5101
 
        if (StringHasNoText (gcfp->append_string))
5102
 
    {
5103
 
      LogGeneToCDSNoProtein (gcfp, context.label, SeqLocId (sfp->location));
5104
 
          return;
5105
 
        }
5106
 
  }
5107
 
  else
5108
 
  {
5109
 
    if (StringHasNoText (qual_val))
5110
 
        {
5111
 
          LogGeneToCDSNoProtein (gcfp, context.label, SeqLocId (sfp->location));
5112
 
          return;
5113
 
        }
5114
 
        prot_len += StringLen (qual_val);
5115
 
  }
5116
 
 
5117
 
  if (!StringHasNoText (gcfp->append_string))
5118
 
  {
5119
 
        if (prot_len > 0)
5120
 
        {
5121
 
          prot_len ++;
5122
 
        }
5123
 
        prot_len += StringLen (gcfp->append_string);
5124
 
  }
5125
 
  if (prot_len == 0)
5126
 
  {
5127
 
        LogGeneToCDSNoProtein (gcfp, context.label, SeqLocId (sfp->location));
5128
 
        return;
5129
 
  }
5130
 
 
5131
 
  /* add one to length for terminating null */
5132
 
  prot_len ++;
5133
 
  protName = (CharPtr) MemNew (prot_len * sizeof (Char));
5134
 
  if (protName == NULL) return;
5135
 
  
5136
 
  if (gene_qual_choice != 1 && !StringHasNoText (qual_val))
5137
 
  {
5138
 
    StringCpy (protName, qual_val);
5139
 
        /* apply capitalization */
5140
 
        switch (gcfp->caps_choice)
5141
 
        {
5142
 
          case 1:
5143
 
            /* do nothing, leave capitalization as is */
5144
 
            break;
5145
 
          case 2:
5146
 
            /* capitalize first letter */
5147
 
            protName [0] = toupper (protName[0]);
5148
 
            break;
5149
 
          case 3:
5150
 
                /* capitalize all letters */
5151
 
                for (cp = protName; *cp != 0; cp++)
5152
 
                {
5153
 
                  *cp = toupper (*cp);
5154
 
                }
5155
 
                break;
5156
 
        }
5157
 
        if (!StringHasNoText (gcfp->append_string))
5158
 
        {
5159
 
          StringCat (protName, " ");
5160
 
        }
5161
 
  }
5162
 
  if (!StringHasNoText (gcfp->append_string))
5163
 
  {
5164
 
    StringCat (protName, gcfp->append_string);
5165
 
  }
5166
 
  
5167
 
  if ((gcfp->gene_qual_choice == gene_qual_choice && gcfp->remove_gene_qual1)
5168
 
    || (gcfp->gene_qual_choice2 == gene_qual_choice && gcfp->remove_gene_qual2)
5169
 
    || (gcfp->gene_qual_choice3 == gene_qual_choice && gcfp->remove_gene_qual3))
5170
 
  {
5171
 
        switch (gene_qual_choice)
5172
 
        {
5173
 
          case 1:
5174
 
            /* do nothing - not using a gene qualifier */
5175
 
            break;
5176
 
          case 2:
5177
 
            grp->locus = MemFree (grp->locus);
5178
 
            break;
5179
 
          case 3:
5180
 
            grp->desc = MemFree (grp->desc);
5181
 
            break;
5182
 
          case 4:
5183
 
            sfp->comment= MemFree (sfp->comment);
5184
 
            break;              
5185
 
        }
5186
 
  }
5187
 
  
5188
 
  cds = SeqFeatNew ();
5189
 
  if (cds == NULL) return;
5190
 
  cds->data.choice = SEQFEAT_CDREGION;
5191
 
 
5192
 
  genCode = SeqEntryToGeneticCode (gcfp->sep, NULL, NULL, 0);
5193
 
  crp = CreateNewCdRgn (1, FALSE, genCode);
5194
 
  if (crp == NULL) {
5195
 
    return;
5196
 
  }
5197
 
 
5198
 
  cds->data.value.ptrvalue = (Pointer) crp;
5199
 
  cds->location = SeqLocFree (cds->location);
5200
 
  cds->location = AsnIoMemCopy ((Pointer) sfp->location,
5201
 
                                (AsnReadFunc) SeqLocAsnRead,
5202
 
                                (AsnWriteFunc) SeqLocAsnWrite);
5203
 
  cds->partial = sfp->partial;
5204
 
  cds->next = sfp->next;
5205
 
  sfp->next = cds;
5206
 
 
5207
 
  bs = ProteinFromCdRegionEx (cds, TRUE, FALSE);
5208
 
  if (bs != NULL) {
5209
 
    prot = BSMerge (bs, NULL);
5210
 
    bs = BSFree (bs);
5211
 
    if (prot != NULL) {
5212
 
      ptr = prot;
5213
 
      ch = *ptr;
5214
 
      while (ch != '\0') {
5215
 
        *ptr = TO_UPPER (ch);
5216
 
        ptr++;
5217
 
        ch = *ptr;
5218
 
      }
5219
 
      i = (Int2) StringLen (prot);
5220
 
      if (i > 0 && prot [i - 1] == '*') {
5221
 
        prot [i - 1] = '\0';
5222
 
      }
5223
 
      bs = BSNew (1000);
5224
 
          if (bs != NULL) {
5225
 
        ptr = prot;
5226
 
        BSWrite (bs, (VoidPtr) ptr, (Int4) StringLen (ptr));
5227
 
      }
5228
 
    }
5229
 
  }
5230
 
  bsp = BioseqNew ();
5231
 
  if (bsp == NULL) return;
5232
 
  bsp->repr = Seq_repr_raw;
5233
 
  bsp->mol = Seq_mol_aa;
5234
 
  bsp->seq_data_type = Seq_code_ncbieaa;
5235
 
  bsp->seq_data = bs;
5236
 
  bsp->length = BSLen (bs);
5237
 
  bs = NULL;
5238
 
  old = SeqEntrySetScope (NULL);
5239
 
  bsp->id = MakeNewProteinSeqId (cds->location, NULL);
5240
 
  SeqMgrAddToBioseqIndex (bsp);
5241
 
  SeqEntrySetScope (old);
5242
 
  psep = SeqEntryNew ();
5243
 
  if (psep != NULL) {
5244
 
    psep->choice = 1;
5245
 
    psep->data.ptrvalue = (Pointer) bsp;
5246
 
    SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) bsp, psep);
5247
 
    mip = MolInfoNew ();
5248
 
    if (mip != NULL) {
5249
 
      mip->biomol = 8;
5250
 
      mip->tech = 8;
5251
 
      if (partial5 && partial3) {
5252
 
        mip->completeness = 5;
5253
 
      } else if (partial5) {
5254
 
        mip->completeness = 3;
5255
 
      } else if (partial3) {
5256
 
        mip->completeness = 4;
5257
 
      }
5258
 
      vnp = CreateNewDescriptor (psep, Seq_descr_molinfo);
5259
 
      if (vnp != NULL) {
5260
 
        vnp->data.ptrvalue = (Pointer) mip;
5261
 
      }
5262
 
    }
5263
 
    descr = ExtractBioSourceAndPubs (gcfp->sep);
5264
 
    if (IS_Bioseq_set (gcfp->sep))
5265
 
    {
5266
 
      topsep = gcfp->sep;
5267
 
    }
5268
 
    else
5269
 
    {
5270
 
      topsep = GetBestTopParentForData (gcfp->input_entityID, gcfp->sep->data.ptrvalue);
5271
 
    }
5272
 
    AddSeqEntryToSeqEntry (topsep, psep, TRUE);
5273
 
    nsep = FindNucSeqEntry (gcfp->sep);
5274
 
    ReplaceBioSourceAndPubs (gcfp->sep, descr);
5275
 
    SetSeqFeatProduct (cds, bsp);
5276
 
    prp = CreateNewProtRef (protName, NULL, NULL, NULL);
5277
 
    MemFree (protName);
5278
 
    sfp = CreateNewFeature (psep, NULL, SEQFEAT_PROT, NULL);
5279
 
    if (sfp != NULL) {
5280
 
       sfp->data.value.ptrvalue = (Pointer) prp;
5281
 
    }
5282
 
  }
5283
 
}
5284
 
 
5285
 
static void GeneToCDSBioseqCallback (BioseqPtr bsp, Pointer userdata)
5286
 
 
5287
 
{
5288
 
  GeneToCDSFormPtr gcfp;
5289
 
 
5290
 
  if (bsp == NULL || userdata == NULL) return;
5291
 
  gcfp = (GeneToCDSFormPtr) userdata;
5292
 
  gcfp->sep = SeqMgrGetSeqEntryForData (bsp);
5293
 
  VisitFeaturesOnBsp (bsp, (Pointer) gcfp, GeneToCDSCallback);
5294
 
}
5295
 
 
5296
 
static void GeneToCdsAccept (ButtoN b)
5297
 
{
5298
 
  GeneToCDSFormPtr gcfp;
5299
 
  Char         path [PATH_MAX];
5300
 
 
5301
 
  gcfp = (GeneToCDSFormPtr) GetObjectExtra (b);
5302
 
  if (gcfp == NULL) return;
5303
 
  TmpNam (path);
5304
 
  gcfp->log_fp = FileOpen (path, "wb");
5305
 
  if (gcfp->log_fp == NULL) return;
5306
 
  
5307
 
  Hide (gcfp->form);
5308
 
  WatchCursor ();
5309
 
  Update ();
5310
 
 
5311
 
  gcfp->sep = GetTopSeqEntryForEntityID (gcfp->input_entityID);
5312
 
  if (gcfp->sep == NULL) return;
5313
 
  
5314
 
  gcfp->gene_qual_choice = GetValue (gcfp->gene_qual_popup);
5315
 
  gcfp->gene_qual_choice2 = GetValue (gcfp->gene_qual_popup2);
5316
 
  gcfp->gene_qual_choice3 = GetValue (gcfp->gene_qual_popup3);
5317
 
  gcfp->append_string = SaveStringFromText (gcfp->append_text);
5318
 
  gcfp->caps_choice = GetValue (gcfp->qual_caps_grp);
5319
 
  gcfp->remove_gene_qual1 = GetStatus (gcfp->remove_qual_btn1);
5320
 
  gcfp->remove_gene_qual2 = GetStatus (gcfp->remove_qual_btn2);
5321
 
  gcfp->remove_gene_qual3 = GetStatus (gcfp->remove_qual_btn3);
5322
 
  
5323
 
  VisitBioseqsInSep (gcfp->sep, (Pointer) gcfp, GeneToCDSBioseqCallback);
5324
 
  
5325
 
  ArrowCursor ();
5326
 
  Update ();
5327
 
  Remove (gcfp->form); 
5328
 
  FileClose (gcfp->log_fp);
5329
 
  if (gcfp->data_in_log)
5330
 
  {
5331
 
    LaunchGeneralTextViewer (path, "Genes without Proteins");
5332
 
  }
5333
 
  FileRemove (path);
5334
 
 
5335
 
  ObjMgrSetDirtyFlag (gcfp->input_entityID, TRUE);
5336
 
  ObjMgrSendMsg (OM_MSG_UPDATE, gcfp->input_entityID, 0, 0);  
5337
 
}
5338
 
 
5339
 
static void CleanupGeneToCDSPage (GraphiC g, VoidPtr data)
5340
 
{
5341
 
  GeneToCDSFormPtr gcfp;
5342
 
 
5343
 
  gcfp = (GeneToCDSFormPtr) data;
5344
 
  if (gcfp != NULL) 
5345
 
  {
5346
 
    gcfp->append_string = MemFree (gcfp->append_string);
5347
 
    MemFree (gcfp);
5348
 
  }
5349
 
}
5350
 
 
5351
 
 
5352
 
static void EnableGeneToCdsControls (GeneToCDSFormPtr gcfp)
5353
 
{
5354
 
  CharPtr cp;
5355
 
  
5356
 
  if (gcfp == NULL) return;
5357
 
  
5358
 
  if (GetValue (gcfp->gene_qual_popup) == 1)
5359
 
  {
5360
 
        Disable (gcfp->remove_qual_btn1);
5361
 
        SetStatus (gcfp->remove_qual_btn1, FALSE);
5362
 
    Disable (gcfp->qual_caps_grp);
5363
 
    SetValue (gcfp->gene_qual_popup2, 1);
5364
 
    Disable (gcfp->remove_qual_btn2);
5365
 
        SetStatus (gcfp->remove_qual_btn2, FALSE);
5366
 
        Disable (gcfp->gene_qual_popup2);
5367
 
    SetValue (gcfp->gene_qual_popup3, 1);
5368
 
        Disable (gcfp->gene_qual_popup3);
5369
 
        Disable (gcfp->remove_qual_btn3);
5370
 
        SetStatus (gcfp->remove_qual_btn3, FALSE);
5371
 
    cp = SaveStringFromText (gcfp->append_text);
5372
 
    if (StringHasNoText (cp))
5373
 
    {
5374
 
      Disable (gcfp->accept_btn);
5375
 
    }
5376
 
    else
5377
 
    {
5378
 
      Enable (gcfp->accept_btn);
5379
 
    }
5380
 
    MemFree (cp);
5381
 
  }
5382
 
  else
5383
 
  {
5384
 
        Enable (gcfp->remove_qual_btn1);
5385
 
        Enable (gcfp->qual_caps_grp);
5386
 
        Enable (gcfp->gene_qual_popup2);
5387
 
        Enable (gcfp->accept_btn);
5388
 
        if (GetValue (gcfp->gene_qual_popup2) == 1)
5389
 
        {
5390
 
          Disable (gcfp->remove_qual_btn2);
5391
 
          SetStatus (gcfp->remove_qual_btn2, FALSE);
5392
 
          SetValue (gcfp->gene_qual_popup3, 1);
5393
 
          Disable (gcfp->gene_qual_popup3);
5394
 
          Disable (gcfp->remove_qual_btn3);
5395
 
          SetStatus (gcfp->remove_qual_btn3, FALSE);
5396
 
        }
5397
 
        else
5398
 
        {
5399
 
          Enable (gcfp->gene_qual_popup3);
5400
 
          Enable (gcfp->remove_qual_btn2);
5401
 
          if (GetValue (gcfp->gene_qual_popup3) == 1)
5402
 
          {
5403
 
                Disable (gcfp->remove_qual_btn3);
5404
 
                SetStatus (gcfp->remove_qual_btn3, FALSE);
5405
 
          }
5406
 
          else
5407
 
          {
5408
 
                Enable (gcfp->remove_qual_btn3);
5409
 
          }
5410
 
        }
5411
 
  }
5412
 
}
5413
 
 
5414
 
static void EnableGeneToCdsControlsPopup (PopuP p)
5415
 
{
5416
 
  GeneToCDSFormPtr gcfp;
5417
 
  
5418
 
  gcfp = (GeneToCDSFormPtr) GetObjectExtra (p);
5419
 
  EnableGeneToCdsControls (gcfp);  
5420
 
}
5421
 
 
5422
 
static void EnableGeneToCdsControlsText (TexT t)
5423
 
{
5424
 
  GeneToCDSFormPtr gcfp;
5425
 
  
5426
 
  gcfp = (GeneToCDSFormPtr) GetObjectExtra (t);
5427
 
  EnableGeneToCdsControls (gcfp);  
5428
 
}
5429
 
 
5430
 
static void GeneToCds (IteM i)
5431
 
 
5432
 
{
5433
 
  BaseFormPtr      bfp;
5434
 
  GeneToCDSFormPtr gcfp;
5435
 
  WindoW           w;
5436
 
  GrouP            h, g, k, m, c;
5437
 
 
5438
 
#ifdef WIN_MAC
5439
 
  bfp = currentFormDataPtr;
5440
 
#else
5441
 
  bfp = GetObjectExtra (i);
5442
 
#endif
5443
 
  if (bfp == NULL) {
5444
 
    Message (MSG_ERROR, "GeneToCDS error");
5445
 
    return;
5446
 
  }
5447
 
  
5448
 
  gcfp = (GeneToCDSFormPtr) MemNew (sizeof (GeneToCDSFormData));
5449
 
  if (gcfp == NULL) return;
5450
 
  gcfp->input_entityID = bfp->input_entityID;
5451
 
  gcfp->input_itemID = bfp->input_itemID;
5452
 
  gcfp->input_itemtype = bfp->input_itemtype;
5453
 
  
5454
 
  w = FixedWindow (-50, -33, -10, -10, "Gene to CDS", StdCloseWindowProc);
5455
 
  SetObjectExtra (w, gcfp, CleanupGeneToCDSPage);
5456
 
  gcfp->form = (ForM) w;
5457
 
 
5458
 
  h = HiddenGroup (w, -1, 0, NULL);
5459
 
  SetGroupSpacing (h, 10, 10);
5460
 
 
5461
 
  g = HiddenGroup (h, 0, 6, NULL);
5462
 
 
5463
 
  k = NormalGroup (g, 3, 0, "Select gene qualifier to use in protein name", NULL, NULL);
5464
 
  StaticPrompt (k, "1st Choice", 0, 0, programFont, 'c');
5465
 
  gcfp->gene_qual_popup = PopupList (k, TRUE, EnableGeneToCdsControlsPopup);
5466
 
  SetObjectExtra (gcfp->gene_qual_popup, gcfp, NULL);
5467
 
  PopupItem (gcfp->gene_qual_popup, "None");
5468
 
  PopupItem (gcfp->gene_qual_popup, "locus");
5469
 
  PopupItem (gcfp->gene_qual_popup, "description");
5470
 
  PopupItem (gcfp->gene_qual_popup, "comment");
5471
 
  SetValue (gcfp->gene_qual_popup, 1);
5472
 
  gcfp->remove_qual_btn1 = CheckBox (k, "Remove if used", NULL);
5473
 
  StaticPrompt (k, "2nd Choice", 0, 0, programFont, 'c');  
5474
 
  gcfp->gene_qual_popup2 = PopupList (k, TRUE, EnableGeneToCdsControlsPopup);
5475
 
  SetObjectExtra (gcfp->gene_qual_popup2, gcfp, NULL);
5476
 
  PopupItem (gcfp->gene_qual_popup2, "None");
5477
 
  PopupItem (gcfp->gene_qual_popup2, "locus");
5478
 
  PopupItem (gcfp->gene_qual_popup2, "description");
5479
 
  PopupItem (gcfp->gene_qual_popup2, "comment");
5480
 
  SetValue (gcfp->gene_qual_popup2, 1);
5481
 
  gcfp->remove_qual_btn2 = CheckBox (k, "Remove if used", NULL);
5482
 
  StaticPrompt (k, "3rd Choice", 0, 0, programFont, 'c');  
5483
 
  gcfp->gene_qual_popup3 = PopupList (k, TRUE, EnableGeneToCdsControlsPopup);
5484
 
  SetObjectExtra (gcfp->gene_qual_popup3, gcfp, NULL);
5485
 
  PopupItem (gcfp->gene_qual_popup3, "None");
5486
 
  PopupItem (gcfp->gene_qual_popup3, "locus");
5487
 
  PopupItem (gcfp->gene_qual_popup3, "description");
5488
 
  PopupItem (gcfp->gene_qual_popup3, "comment");
5489
 
  SetValue (gcfp->gene_qual_popup3, 1);
5490
 
  gcfp->remove_qual_btn3 = CheckBox (k, "Remove if used", NULL);
5491
 
  
5492
 
  gcfp->qual_caps_grp = NormalGroup (g, 3, 0,
5493
 
                     "Capitalization for gene qualifier in protein name", NULL, NULL);
5494
 
  RadioButton (gcfp->qual_caps_grp, "As is");
5495
 
  RadioButton (gcfp->qual_caps_grp, "Capitalize first initial");
5496
 
  RadioButton (gcfp->qual_caps_grp, "Capitalize all");
5497
 
  SetValue (gcfp->qual_caps_grp, 1);
5498
 
  
5499
 
  m = HiddenGroup (g, 0, 2, NULL);
5500
 
  StaticPrompt (m, "Append text to protein name", 0, 0, programFont, 'c');
5501
 
  gcfp->append_text = DialogText (m, "", 14, EnableGeneToCdsControlsText); 
5502
 
  SetObjectExtra (gcfp->append_text, gcfp, NULL);
5503
 
   
5504
 
  c = HiddenGroup (g, 4, 0, NULL); 
5505
 
  gcfp->accept_btn = PushButton (c, "Accept", GeneToCdsAccept);
5506
 
  SetObjectExtra (gcfp->accept_btn, gcfp, NULL);
5507
 
  EnableGeneToCdsControls (gcfp);
5508
 
  
5509
 
  PushButton (c, "Cancel", StdCancelButtonProc);
5510
 
 
5511
 
 
5512
 
  AlignObjects (ALIGN_CENTER, (HANDLE) k, (HANDLE) gcfp->qual_caps_grp,
5513
 
                (HANDLE) m, (HANDLE) c, NULL);
5514
 
                
5515
 
  RealizeWindow (w);
5516
 
  Show (w);
5517
 
  Update ();
5518
 
  
5519
 
}
5520
5402
 
5521
5403
typedef struct featuretocdsform
5522
5404
{
6368
6250
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
6369
6251
}
6370
6252
 
 
6253
static void ForcePackageFeatureCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
 
6254
 
 
6255
{
 
6256
  BaseFormPtr    bfp;
 
6257
  BioseqPtr      bsp = NULL;
 
6258
  BioseqSetPtr   bssp = NULL;
 
6259
  SeqAnnotPtr    firstsap;
 
6260
  SeqAnnotPtr    nextsap;
 
6261
  SeqFeatPtr     nextsfp;
 
6262
  Pointer PNTR   prevsap;
 
6263
  Pointer PNTR   prevsfp;
 
6264
  SeqAnnotPtr    sap;
 
6265
  SeqFeatPtr     sfp;
 
6266
  BioseqPtr      target;
 
6267
 
 
6268
  if (sep == NULL || sep->data.ptrvalue == NULL) return;
 
6269
  bfp = (BaseFormPtr) mydata;
 
6270
  if (bfp == NULL) return;
 
6271
  if (IS_Bioseq (sep)) {
 
6272
    bsp = (BioseqPtr) sep->data.ptrvalue;
 
6273
    sap = bsp->annot;
 
6274
    prevsap = (Pointer PNTR) &(bsp->annot);
 
6275
  } else if (IS_Bioseq_set (sep)) {
 
6276
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
 
6277
    sap = bssp->annot;
 
6278
    prevsap = (Pointer PNTR) &(bssp->annot);
 
6279
  } else return;
 
6280
  firstsap = sap;
 
6281
  while (sap != NULL) {
 
6282
    nextsap = sap->next;
 
6283
    if (sap->type == 1) {
 
6284
      sfp = (SeqFeatPtr) sap->data;
 
6285
      prevsfp = (Pointer PNTR) &(sap->data);
 
6286
      while (sfp != NULL) {
 
6287
        nextsfp = sfp->next;
 
6288
        target = GetBioseqGivenSeqLoc (sfp->location, bfp->input_entityID);
 
6289
        if (target != bsp || sap != firstsap) {
 
6290
          *(prevsfp) = sfp->next;
 
6291
          sfp->next = NULL;
 
6292
          AddFeatureToBioseq (sfp, target);
 
6293
        } else {
 
6294
          prevsfp = (Pointer PNTR) &(sfp->next);
 
6295
        }
 
6296
        sfp = nextsfp;
 
6297
      }
 
6298
    }
 
6299
    if (sap->data == NULL) {
 
6300
      *(prevsap) = sap->next;
 
6301
      sap->next = NULL;
 
6302
      SeqAnnotFree (sap);
 
6303
    } else {
 
6304
      prevsap = (Pointer PNTR) &(sap->next);
 
6305
    }
 
6306
    sap = nextsap;
 
6307
  }
 
6308
}
 
6309
 
 
6310
static void ForceRepackage (IteM i)
 
6311
 
 
6312
{
 
6313
  BaseFormPtr  bfp;
 
6314
  SeqEntryPtr  sep;
 
6315
 
 
6316
#ifdef WIN_MAC
 
6317
  bfp = currentFormDataPtr;
 
6318
#else
 
6319
  bfp = GetObjectExtra (i);
 
6320
#endif
 
6321
  if (bfp == NULL) return;
 
6322
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
6323
  if (sep == NULL) return;
 
6324
  WatchCursor ();
 
6325
  Update ();
 
6326
  SeqEntryExplore (sep, bfp, ForcePackageFeatureCallback);
 
6327
  ArrowCursor ();
 
6328
  Update ();
 
6329
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
6330
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
6331
}
 
6332
 
6371
6333
static BioseqSetPtr GetParentNPS (BioseqPtr bsp)
6372
6334
{
6373
6335
  BioseqSetPtr  bssp;
7287
7249
  }
7288
7250
}
7289
7251
 
7290
 
/*---------------------------------------------------------------------*/
7291
 
/*                                                                     */
7292
 
/* ConvertCDS_FeatureCallback () -- Called once for each CDS feature   */
7293
 
/*                                  on a Bioseq.  This function does   */
7294
 
/*                                  the actual CDS deleting.           */
7295
 
/*                                                                     */
7296
 
/*---------------------------------------------------------------------*/
7297
 
 
7298
 
static Boolean LIBCALLBACK ConvertCDS_FeatureCallback (SeqFeatPtr sfp,
7299
 
                                        SeqMgrFeatContextPtr fcontext)
 
7252
extern void ConvertCDSToMiscFeat (SeqFeatPtr sfp)
7300
7253
{
7301
7254
  CdRegionPtr          cdrp;
7302
7255
  GBQualPtr            gbqual;
7309
7262
  ProtRefPtr           prp;
7310
7263
  ValNodePtr           vnp;
7311
7264
 
7312
 
  /* skip CDSs without products */
7313
 
  if (sfp == NULL || sfp->product == NULL) return TRUE;
7314
 
 
7315
 
  /* If no internal stop codons, then done */
7316
 
 
7317
 
  if (FALSE == HasInternalStops(sfp))
7318
 
    return TRUE;
7319
 
 
 
7265
  if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION)
 
7266
  {
 
7267
    return;
 
7268
  }
 
7269
  
7320
7270
  /* Get the CD region part of the feature, and */
7321
7271
  /* the associated protein bioseq.             */
7322
7272
 
7323
7273
  cdrp = (CdRegionPtr) sfp->data.value.ptrvalue;
7324
7274
  protBsp = BioseqFindFromSeqLoc (sfp->product);
7325
7275
 
7326
 
  if (protBsp == NULL) return TRUE;
 
7276
  if (protBsp == NULL) return;
7327
7277
 
7328
7278
  /* Convert the CDS feature to a misc_feat */
7329
7279
 
7331
7281
  sfp->data.value.ptrvalue = NULL;
7332
7282
 
7333
7283
  ifp = ImpFeatNew ();
7334
 
  if (NULL == ifp)
7335
 
    return FALSE;
 
7284
  if (NULL == ifp) return;
7336
7285
  ifp->key = StringSave ("misc_feature");
7337
7286
 
7338
7287
  sfp->data.choice = SEQFEAT_IMP;
7342
7291
  /* Add a name key to the misc_feature */
7343
7292
 
7344
7293
  protSfp = SeqMgrGetBestProteinFeature (protBsp, &protContext);
7345
 
  prp = (ProtRefPtr) protSfp->data.value.ptrvalue;
 
7294
  if (protSfp != NULL)
 
7295
  {
 
7296
    prp = (ProtRefPtr) protSfp->data.value.ptrvalue;
7346
7297
 
7347
 
  if (prp != NULL) {
7348
 
    vnp = prp->name;
7349
 
    if (NULL != vnp)
 
7298
    if (prp != NULL) 
 
7299
    {
 
7300
      vnp = prp->name;
 
7301
      if (NULL != vnp)
7350
7302
      {
7351
 
        protName = (CharPtr) vnp->data.ptrvalue;
7352
 
        if (NULL != protName) {
7353
 
          noteStr = (CharPtr) MemNew (StringLen (protName) + 12);
7354
 
          sprintf (noteStr, "similar to %s", protName);
7355
 
        }
 
7303
        protName = (CharPtr) vnp->data.ptrvalue;
 
7304
        if (NULL != protName) 
 
7305
        {
 
7306
                noteStr = (CharPtr) MemNew (StringLen (protName) + 12);
 
7307
          sprintf (noteStr, "similar to %s", protName);
 
7308
          gbqual = GBQualNew ();
 
7309
          if (gbqual != NULL) 
 
7310
          {
 
7311
            gbqual->qual = StringSave ("note");
 
7312
            gbqual->val = noteStr;
 
7313
            gbqual->next = sfp->qual;
 
7314
            sfp->qual = gbqual;
 
7315
          }
 
7316
          else
 
7317
          {
 
7318
            noteStr = MemFree (noteStr);
 
7319
          }
 
7320
        }
7356
7321
      }
 
7322
    }
7357
7323
  }
7358
7324
 
7359
 
  gbqual = GBQualNew ();
7360
 
  if (gbqual == NULL)
7361
 
    return FALSE;
7362
 
 
7363
 
  gbqual->qual = StringSave ("note");
7364
 
  gbqual->val = noteStr;
7365
 
  gbqual->next = sfp->qual;
7366
 
  sfp->qual = gbqual;
7367
 
 
7368
7325
  /* Delete the protein Bioseq that */
7369
7326
  /* the CDS points to.             */
7370
7327
 
7372
7329
 
7373
7330
  /* set the subtype to zero so that it will be reindexed */
7374
7331
  sfp->idx.subtype = 0;
 
7332
}
 
7333
 
 
7334
/*---------------------------------------------------------------------*/
 
7335
/*                                                                     */
 
7336
/* ConvertCDS_FeatureCallback () -- Called once for each CDS feature   */
 
7337
/*                                  on a Bioseq.  This function does   */
 
7338
/*                                  the actual CDS deleting.           */
 
7339
/*                                                                     */
 
7340
/*---------------------------------------------------------------------*/
 
7341
 
 
7342
static Boolean LIBCALLBACK ConvertCDS_FeatureCallback (SeqFeatPtr sfp,
 
7343
                                        SeqMgrFeatContextPtr fcontext)
 
7344
{
 
7345
 
 
7346
  /* skip CDSs without products */
 
7347
  if (sfp == NULL || sfp->product == NULL) return TRUE;
 
7348
 
 
7349
  /* If no internal stop codons, then done */
 
7350
 
 
7351
  if (FALSE == HasInternalStops(sfp))
 
7352
    return TRUE;
 
7353
 
 
7354
  ConvertCDSToMiscFeat (sfp);
7375
7355
  
7376
7356
  /* Return TRUE to continue on to the next CDS feature */
7377
7357
 
7445
7425
 
7446
7426
  DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
7447
7427
  SeqMgrLinkSeqEntry (sep, parenttype, parentptr);
 
7428
  
 
7429
  if (ANS_YES == Message (MSG_YN, "Renormalize Nuc-Prot sets?"))
 
7430
  {
 
7431
    RenormalizeNucProtSets (sep, TRUE);         
 
7432
  }
 
7433
 
 
7434
  
7448
7435
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
7449
7436
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
7450
7437
  ArrowCursor ();
8458
8445
  Boolean            overshot = FALSE;
8459
8446
  SeqFeatPtr         prevCdsSfp = NULL;
8460
8447
  SeqFeatXrefPtr     prevXref = NULL;
8461
 
  SeqMgrFeatContext  rbsContext;
 
8448
  SeqMgrFeatContext  rbsContext, geneContext;
8462
8449
  GeneRefPtr         rbsGrp;
8463
8450
  Int4               rbsLeft;
8464
8451
  Int4               rbsRight;
8487
8474
  /* Loop through all RBS features */
8488
8475
 
8489
8476
  while (NULL != rbsSfp)
8490
 
    {
8491
 
 
8492
 
      /* If the feature has an existing gene xref */
8493
 
      /* then we need to delete it.               */
8494
 
  
8495
 
      xref = rbsSfp->xref;
8496
 
      while (xref != NULL && xref->data.choice != SEQFEAT_GENE)
8497
 
        {
8498
 
          prevXref = xref;
8499
 
          xref = xref->next;
8500
 
        }
8501
 
      
8502
 
      if (xref != NULL)
8503
 
        {
8504
 
          rbsGrp = (GeneRefPtr) xref->data.value.ptrvalue;
8505
 
          rbsGrp = GeneRefFree (rbsGrp);
8506
 
          if (prevXref != NULL)
8507
 
            prevXref->next = xref->next;
8508
 
          else
8509
 
            rbsSfp->xref = xref->next;
8510
 
          SeqFeatXrefFree (xref);
8511
 
          xref = NULL;
8512
 
        }
8513
 
 
8514
 
      /* Search for a 'downstream' gene xref */
8515
 
  
8516
 
      if (overshot)
8517
 
        overshot = FALSE;
8518
 
      else
8519
 
        {
8520
 
          prevCdsSfp = cdsSfp;
8521
 
          cdsSfp = SeqMgrGetNextFeature (bsp, cdsSfp, 0, FEATDEF_CDS,
8522
 
                                         &cdsContext);
8523
 
        }
8524
 
      
8525
 
      rbsSlp  = rbsSfp->location;
8526
 
      strand  = SeqLocStrand (rbsSlp);
8527
 
 
8528
 
      if (strand == Seq_strand_plus)
8529
 
        {
8530
 
          /* If the gene starts at or 'after' the  */
8531
 
          /* RBS, then the RBS probably belongs to */
8532
 
          /* it, so make that gene a xref for the  */
8533
 
          /* RBS feature.                          */
 
8477
  {
 
8478
    /* If the feature has an existing gene xref */
 
8479
    /* then we need to delete it.               */
 
8480
  
 
8481
    xref = rbsSfp->xref;
 
8482
    while (xref != NULL && xref->data.choice != SEQFEAT_GENE)
 
8483
          {
 
8484
            prevXref = xref;
 
8485
            xref = xref->next;
 
8486
          }
 
8487
      
 
8488
    if (xref != NULL)
 
8489
          {
 
8490
            if (prevXref != NULL)
 
8491
              prevXref->next = xref->next;
 
8492
            else
 
8493
              rbsSfp->xref = xref->next;
 
8494
            xref->next = NULL;
 
8495
            SeqFeatXrefFree (xref);
 
8496
            xref = NULL;
 
8497
          }
 
8498
 
 
8499
    /* Search for a 'downstream' gene xref */
 
8500
  
 
8501
    if (overshot)
 
8502
            overshot = FALSE;
 
8503
    else
 
8504
    {
 
8505
            prevCdsSfp = cdsSfp;
 
8506
            cdsSfp = SeqMgrGetNextFeature (bsp, cdsSfp, 0, FEATDEF_CDS,
 
8507
                                                                   &cdsContext);
 
8508
    }
 
8509
      
 
8510
    rbsSlp  = rbsSfp->location;
 
8511
    strand  = SeqLocStrand (rbsSlp);
 
8512
 
 
8513
    if (strand == Seq_strand_plus)
 
8514
    {
 
8515
            /* If the gene starts at or 'after' the  */
 
8516
            /* RBS, then the RBS probably belongs to */
 
8517
            /* it, so make that gene a xref for the  */
 
8518
            /* RBS feature.                          */
8534
8519
          
8535
 
          found = FALSE;
8536
 
          while ((cdsSfp != NULL) && (!found))
 
8520
            found = FALSE;
 
8521
            while ((cdsSfp != NULL) && (!found))
8537
8522
            {
8538
8523
              cdsSlp  = cdsSfp->location;
8539
8524
              cdsLeft = GetOffsetInBioseq (cdsSlp, bsp,
8541
8526
              rbsLeft = GetOffsetInBioseq (rbsSlp , bsp,
8542
8527
                                           SEQLOC_LEFT_END);
8543
8528
              if (rbsLeft <= cdsLeft)
8544
 
                {
8545
 
                  found = TRUE;
8546
 
                  geneSfp = SeqMgrGetOverlappingGene (cdsSlp, NULL);
8547
 
                  if (geneSfp != NULL) {
8548
 
                    geneGrp = (GeneRefPtr) geneSfp->data.value.ptrvalue;
8549
 
                    rbsGrp = CopyGeneRef (geneGrp);
8550
 
                    if (rbsGrp != NULL)
8551
 
                      {
8552
 
                        xref = SeqFeatXrefNew ();
8553
 
                        xref->data.choice = SEQFEAT_GENE;
8554
 
                        xref->data.value.ptrvalue = rbsGrp;
8555
 
                        xref->next = rbsSfp->xref;
8556
 
                        rbsSfp->xref = xref;
8557
 
                      }
8558
 
                  }
8559
 
                }
 
8529
        {
 
8530
          found = TRUE;
 
8531
          geneSfp = SeqMgrGetOverlappingGene (cdsSlp, &geneContext);
 
8532
          if (geneSfp != NULL) {
 
8533
            geneGrp = (GeneRefPtr) geneSfp->data.value.ptrvalue;
 
8534
            rbsGrp = CopyGeneRef (geneGrp);
 
8535
            if (rbsGrp != NULL)
 
8536
            {
 
8537
                          xref = SeqFeatXrefNew ();
 
8538
                          xref->data.choice = SEQFEAT_GENE;
 
8539
                          xref->data.value.ptrvalue = rbsGrp;
 
8540
                          xref->next = rbsSfp->xref;
 
8541
                          rbsSfp->xref = xref;
 
8542
                        }
 
8543
                        
 
8544
                        /* enlarge gene to cover RBS */
 
8545
                        if (geneContext.left > rbsContext.left)
 
8546
                        {
 
8547
              ExtendSeqLocToPosition (geneSfp->location, TRUE, rbsContext.left);
 
8548
                        }
 
8549
                        
 
8550
          }
 
8551
        }
8560
8552
              else
8561
 
                {
8562
 
                  if (overshot)
8563
 
                    overshot = FALSE;
8564
 
                  else
8565
 
                    {
8566
 
                      prevCdsSfp = cdsSfp;
8567
 
                      cdsSfp = SeqMgrGetNextFeature (bsp, cdsSfp, 0,
8568
 
                                                     FEATDEF_CDS,
8569
 
                                                     &cdsContext);
8570
 
                    }
8571
 
                }
 
8553
        {
 
8554
          if (overshot)
 
8555
            overshot = FALSE;
 
8556
          else
 
8557
          {
 
8558
            prevCdsSfp = cdsSfp;
 
8559
            cdsSfp = SeqMgrGetNextFeature (bsp, cdsSfp, 0,
 
8560
                                           FEATDEF_CDS,
 
8561
                                           &cdsContext);
 
8562
          }
 
8563
        }
8572
8564
            }
8573
 
        }
8574
 
      else if (strand == Seq_strand_minus)
8575
 
        {
8576
 
          found = FALSE;
8577
 
          while ((cdsSfp != NULL) && (!found))
8578
 
            {
8579
 
              cdsSlp   = cdsSfp->location;
8580
 
              cdsRight = GetOffsetInBioseq (cdsSlp, bsp,
8581
 
                                            SEQLOC_RIGHT_END);
8582
 
              rbsRight = GetOffsetInBioseq (rbsSlp , bsp,
8583
 
                                            SEQLOC_RIGHT_END);
8584
 
              if (cdsRight > rbsRight)
8585
 
                {
8586
 
                  found = TRUE;
8587
 
                  if (prevCdsSfp != NULL)
8588
 
                    {
8589
 
                      overshot = TRUE;
8590
 
                      geneSfp = SeqMgrGetOverlappingGene (prevCdsSfp->location,
8591
 
                                                          NULL);
8592
 
                      if (geneSfp != NULL) {
8593
 
                        geneGrp = (GeneRefPtr) geneSfp->data.value.ptrvalue;
8594
 
                        rbsGrp = CopyGeneRef (geneGrp);
8595
 
                        if (rbsGrp != NULL)
8596
 
                          {
8597
 
                            xref = SeqFeatXrefNew ();
8598
 
                            xref->data.choice = SEQFEAT_GENE;
8599
 
                            xref->data.value.ptrvalue = rbsGrp;
8600
 
                            xref->next = rbsSfp->xref;
8601
 
                            rbsSfp->xref = xref;
8602
 
                          }
8603
 
                      }
 
8565
    }
 
8566
    else if (strand == Seq_strand_minus)
 
8567
    {
 
8568
            found = FALSE;
 
8569
            while ((cdsSfp != NULL) && (!found))
 
8570
      {
 
8571
        cdsSlp   = cdsSfp->location;
 
8572
        cdsRight = GetOffsetInBioseq (cdsSlp, bsp,
 
8573
                                      SEQLOC_RIGHT_END);
 
8574
        rbsRight = GetOffsetInBioseq (rbsSlp , bsp,
 
8575
                                      SEQLOC_RIGHT_END);
 
8576
        if (cdsRight > rbsRight)
 
8577
        {
 
8578
          found = TRUE;
 
8579
          if (prevCdsSfp != NULL)
 
8580
          {
 
8581
            overshot = TRUE;
 
8582
            geneSfp = SeqMgrGetOverlappingGene (prevCdsSfp->location,
 
8583
                                                NULL);
 
8584
            if (geneSfp != NULL) {
 
8585
              geneGrp = (GeneRefPtr) geneSfp->data.value.ptrvalue;
 
8586
              rbsGrp = CopyGeneRef (geneGrp);
 
8587
              if (rbsGrp != NULL)
 
8588
              {
 
8589
                xref = SeqFeatXrefNew ();
 
8590
                xref->data.choice = SEQFEAT_GENE;
 
8591
                xref->data.value.ptrvalue = rbsGrp;
 
8592
                xref->next = rbsSfp->xref;
 
8593
                rbsSfp->xref = xref;
 
8594
              }
 
8595
              
 
8596
                          /* enlarge gene to cover RBS */
 
8597
                          if (geneContext.right < rbsContext.right)
 
8598
                          {
 
8599
                ExtendSeqLocToPosition (geneSfp->location, TRUE, rbsContext.right);
 
8600
                          }
 
8601
              
 
8602
            }
8604
8603
                        
8605
 
                    }
8606
 
                }
8607
 
              else
8608
 
                {
8609
 
                  if (overshot)
8610
 
                    overshot = FALSE;
8611
 
                  else
8612
 
                    {
8613
 
                      prevCdsSfp = cdsSfp;
8614
 
                      cdsSfp = SeqMgrGetNextFeature (bsp, cdsSfp, 0,
8615
 
                                                     FEATDEF_CDS,
8616
 
                                                     &cdsContext);
8617
 
                    }
8618
 
                }
 
8604
          }
 
8605
        }
 
8606
        else
 
8607
        {
 
8608
          if (overshot)
 
8609
            overshot = FALSE;
 
8610
          else
 
8611
          {
 
8612
            prevCdsSfp = cdsSfp;
 
8613
            cdsSfp = SeqMgrGetNextFeature (bsp, cdsSfp, 0,
 
8614
                                           FEATDEF_CDS,
 
8615
                                           &cdsContext);
 
8616
          }
 
8617
        }
8619
8618
              
8620
 
            }
8621
 
        }
 
8619
      }
 
8620
    }
8622
8621
      
8623
 
      rbsSfp  = SeqMgrGetNextFeature (bsp, rbsSfp, 0, FEATDEF_RBS, &rbsContext);
8624
 
    }
 
8622
    rbsSfp  = SeqMgrGetNextFeature (bsp, rbsSfp, 0, FEATDEF_RBS, &rbsContext);
 
8623
  }
8625
8624
 
8626
8625
  /* Force an update and redraw */
8627
8626
 
8939
8938
  mibp->strand_values = NULL;
8940
8939
}
8941
8940
 
 
8941
 
 
8942
typedef struct sequenceconstraint 
 
8943
{
 
8944
  Boolean nucs_ok;
 
8945
  Boolean prots_ok;
 
8946
  
 
8947
  Int4                other_constraint_type;
 
8948
  StringConstraintPtr string_constraint;
 
8949
  ChoiceConstraintPtr source_constraint;
 
8950
  ValNodePtr          feature_list;
 
8951
  
 
8952
} SequenceConstraintData, PNTR SequenceConstraintPtr;
 
8953
 
 
8954
 
 
8955
static SequenceConstraintPtr SequenceConstraintFree (SequenceConstraintPtr scp)
 
8956
{
 
8957
  if (scp != NULL)
 
8958
  {
 
8959
    scp->string_constraint = StringConstraintFree (scp->string_constraint);
 
8960
    scp->source_constraint = ChoiceConstraintFree (scp->source_constraint);
 
8961
    scp->feature_list = ValNodeFree (scp->feature_list);
 
8962
    scp = MemFree (scp);
 
8963
  }
 
8964
  return scp;
 
8965
}
 
8966
 
 
8967
 
 
8968
typedef struct sequenceconstraintdlg 
 
8969
{
 
8970
  DIALOG_MESSAGE_BLOCK
 
8971
  GrouP  seq_type_constraint;
 
8972
  GrouP  other_constraint_type;
 
8973
  DialoG source_constraint;
 
8974
  DialoG feature_list;
 
8975
  DialoG feature_string_constraint;
 
8976
  DialoG id_string_constraint;
 
8977
  
 
8978
} SequenceConstraintDlgData, PNTR SequenceConstraintDlgPtr;
 
8979
 
 
8980
 
 
8981
enum sequenceconstraintothertype 
 
8982
{
 
8983
  SEQ_CONSTRAINT_ANY = 0,
 
8984
  SEQ_CONSTRAINT_SOURCE,
 
8985
  SEQ_CONSTRAINT_FEATURE_TEXT,
 
8986
  SEQ_CONSTRAINT_ID
 
8987
};
 
8988
 
 
8989
 
 
8990
static void ChangeSequenceConstraintType (GrouP g)
 
8991
{
 
8992
  SequenceConstraintDlgPtr scdp;
 
8993
  Int4                     other_constraint_type;
 
8994
  
 
8995
  scdp = (SequenceConstraintDlgPtr) GetObjectExtra (g);
 
8996
  if (scdp == NULL)
 
8997
  {
 
8998
    return;
 
8999
  }
 
9000
  other_constraint_type = (GetValue (scdp->other_constraint_type) - 1) / 2;
 
9001
  Disable (scdp->source_constraint);
 
9002
  Disable (scdp->feature_string_constraint);
 
9003
  Disable (scdp->id_string_constraint);
 
9004
  if (other_constraint_type == SEQ_CONSTRAINT_SOURCE)
 
9005
  {
 
9006
    Enable (scdp->source_constraint);
 
9007
  }
 
9008
  else if (other_constraint_type == SEQ_CONSTRAINT_FEATURE_TEXT)
 
9009
  {
 
9010
    Enable (scdp->feature_string_constraint);
 
9011
  }
 
9012
  else if (other_constraint_type == SEQ_CONSTRAINT_ID)
 
9013
  {
 
9014
    Enable (scdp->id_string_constraint);
 
9015
  }
 
9016
}
 
9017
 
 
9018
static void ResetSequenceConstraintDialog (DialoG d)
 
9019
{
 
9020
  SequenceConstraintDlgPtr scdp;
 
9021
  
 
9022
  scdp = (SequenceConstraintDlgPtr) GetObjectExtra (d);
 
9023
  if (scdp == NULL)
 
9024
  {
 
9025
    return;
 
9026
  }
 
9027
  
 
9028
  SetValue (scdp->seq_type_constraint, 1);
 
9029
  SetValue (scdp->other_constraint_type, SEQ_CONSTRAINT_ANY + 1);
 
9030
  ChangeSequenceConstraintType (scdp->other_constraint_type);
 
9031
}
 
9032
 
 
9033
static void SequenceConstraintToDialog (DialoG d, Pointer data)
 
9034
{
 
9035
  SequenceConstraintPtr    scp;
 
9036
  SequenceConstraintDlgPtr scdp;
 
9037
  
 
9038
  scdp = (SequenceConstraintDlgPtr) GetObjectExtra (d);
 
9039
  if (scdp == NULL)
 
9040
  {
 
9041
    return;
 
9042
  }
 
9043
  
 
9044
  scp = (SequenceConstraintPtr) data;
 
9045
  
 
9046
  if (scp == NULL)
 
9047
  {
 
9048
    ResetSequenceConstraintDialog (d);
 
9049
  }
 
9050
  else
 
9051
  {
 
9052
    if (scp->nucs_ok && scp->prots_ok)
 
9053
    {
 
9054
      SetValue (scdp->seq_type_constraint, 1);
 
9055
    }
 
9056
    else if (scp->nucs_ok)
 
9057
    {
 
9058
      SetValue (scdp->seq_type_constraint, 2);
 
9059
    }
 
9060
    else
 
9061
    {
 
9062
      SetValue (scdp->seq_type_constraint, 3);
 
9063
    }
 
9064
    SetValue (scdp->other_constraint_type, scp->other_constraint_type + 1);
 
9065
    switch (scp->other_constraint_type)
 
9066
    {
 
9067
      case SEQ_CONSTRAINT_SOURCE:
 
9068
          PointerToDialog (scdp->source_constraint, scp->source_constraint);
 
9069
          break;
 
9070
      case SEQ_CONSTRAINT_FEATURE_TEXT:
 
9071
          PointerToDialog (scdp->feature_string_constraint, scp->string_constraint);
 
9072
          PointerToDialog (scdp->feature_list, scp->feature_list);
 
9073
          break;
 
9074
      case SEQ_CONSTRAINT_ID:
 
9075
          PointerToDialog (scdp->id_string_constraint, scp->string_constraint);
 
9076
          break;
 
9077
    }
 
9078
    ChangeSequenceConstraintType (scdp->other_constraint_type);
 
9079
  }
 
9080
}
 
9081
 
 
9082
 
 
9083
static Pointer DialogToSequenceConstraint (DialoG d)
 
9084
{
 
9085
  SequenceConstraintPtr    scp;
 
9086
  SequenceConstraintDlgPtr scdp;
 
9087
  
 
9088
  scdp = (SequenceConstraintDlgPtr) GetObjectExtra (d);
 
9089
  if (scdp == NULL)
 
9090
  {
 
9091
    return;
 
9092
  }
 
9093
  
 
9094
  scp = (SequenceConstraintPtr) MemNew (sizeof (SequenceConstraintData));
 
9095
  if (scp != NULL)
 
9096
  {
 
9097
    switch (GetValue (scdp->seq_type_constraint))
 
9098
    {
 
9099
      case 1:
 
9100
        scp->nucs_ok = TRUE;
 
9101
        scp->prots_ok = TRUE;
 
9102
        break;
 
9103
      case 2:
 
9104
        scp->nucs_ok = TRUE;
 
9105
        break;
 
9106
      case 3:
 
9107
        scp->prots_ok = TRUE;
 
9108
        break;
 
9109
    }
 
9110
    
 
9111
    scp->other_constraint_type = (GetValue (scdp->other_constraint_type) - 1)/2;
 
9112
    switch (scp->other_constraint_type)
 
9113
    {
 
9114
      case SEQ_CONSTRAINT_SOURCE:
 
9115
        scp->source_constraint = DialogToPointer (scdp->source_constraint);
 
9116
        break;
 
9117
      case SEQ_CONSTRAINT_FEATURE_TEXT:
 
9118
        scp->string_constraint = DialogToPointer (scdp->feature_string_constraint);
 
9119
        scp->feature_list = DialogToPointer (scdp->feature_list);
 
9120
        break;
 
9121
      case SEQ_CONSTRAINT_ID:
 
9122
        scp->string_constraint = DialogToPointer (scdp->id_string_constraint);
 
9123
        break;
 
9124
    }
 
9125
  }
 
9126
  return scp;
 
9127
}
 
9128
 
 
9129
 
 
9130
static void SequenceConstraintMessage (DialoG d, Int2 mssg)
 
9131
 
 
9132
{
 
9133
  SequenceConstraintDlgPtr scdp;
 
9134
 
 
9135
  scdp = (SequenceConstraintDlgPtr) GetObjectExtra (d);
 
9136
  if (scdp != NULL) {
 
9137
    switch (mssg) {
 
9138
      case VIB_MSG_INIT :
 
9139
        ResetSequenceConstraintDialog (d);        
 
9140
        break;
 
9141
      case VIB_MSG_ENTER :
 
9142
        Select (scdp->other_constraint_type);
 
9143
        break;
 
9144
      default :
 
9145
        break;
 
9146
    }
 
9147
  }
 
9148
}
 
9149
 
 
9150
static ValNodePtr TestSequenceConstraintDialog (DialoG d)
 
9151
 
 
9152
{
 
9153
  return NULL;
 
9154
}
 
9155
 
 
9156
 
 
9157
static DialoG SequenceConstraintDialog (GrouP g)
 
9158
{
 
9159
  SequenceConstraintDlgPtr dlg;
 
9160
  GrouP p, k;
 
9161
  
 
9162
  dlg = (SequenceConstraintDlgPtr) MemNew (sizeof (SequenceConstraintDlgData));
 
9163
  if (dlg == NULL) return NULL;
 
9164
 
 
9165
  p = HiddenGroup (g, -1, 0, NULL);
 
9166
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
 
9167
  SetGroupSpacing (p, 10, 10);
 
9168
 
 
9169
  dlg->dialog = (DialoG) p;
 
9170
  dlg->todialog = SequenceConstraintToDialog;
 
9171
  dlg->fromdialog = DialogToSequenceConstraint;
 
9172
  dlg->dialogmessage = SequenceConstraintMessage;
 
9173
  dlg->testdialog = TestSequenceConstraintDialog;
 
9174
 
 
9175
  dlg->seq_type_constraint = HiddenGroup (p, 4, 0, NULL);
 
9176
  RadioButton (dlg->seq_type_constraint, "All Sequences");
 
9177
  RadioButton (dlg->seq_type_constraint, "Nucleotides");
 
9178
  RadioButton (dlg->seq_type_constraint, "Proteins");
 
9179
  SetValue (dlg->seq_type_constraint, 2);
 
9180
 
 
9181
  dlg->other_constraint_type = HiddenGroup (p, 2, 0, ChangeSequenceConstraintType);
 
9182
  RadioButton (dlg->other_constraint_type, "Any sequence");
 
9183
  StaticPrompt (dlg->other_constraint_type, "", 0, dialogTextHeight, systemFont, 'l');  
 
9184
  
 
9185
  RadioButton (dlg->other_constraint_type, "Where sequence source");
 
9186
  dlg->source_constraint = SourceConstraintDialog (dlg->other_constraint_type, FALSE);
 
9187
    
 
9188
  RadioButton (dlg->other_constraint_type, "Where feature text");
 
9189
  k = HiddenGroup (dlg->other_constraint_type, 2, 0, NULL);
 
9190
  SetGroupSpacing (k, 10, 10);
 
9191
  dlg->feature_list = FeatureSelectionDialog (k, TRUE, NULL, NULL);
 
9192
  dlg->feature_string_constraint = StringConstraintDialog (k, NULL, FALSE);
 
9193
    
 
9194
  RadioButton (dlg->other_constraint_type, "Where sequence ID");
 
9195
  dlg->id_string_constraint = StringConstraintDialog (dlg->other_constraint_type, NULL, FALSE);
 
9196
  
 
9197
  SetValue (dlg->other_constraint_type, CHOICE_CONSTRAINT_ANY);
 
9198
  SetObjectExtra (dlg->other_constraint_type, dlg, NULL);
 
9199
 
 
9200
  Disable (dlg->source_constraint);
 
9201
  Disable (dlg->feature_string_constraint);
 
9202
  Disable (dlg->id_string_constraint);
 
9203
    
 
9204
  AlignObjects (ALIGN_CENTER, (HANDLE) dlg->seq_type_constraint, 
 
9205
                              (HANDLE) dlg->other_constraint_type, NULL);
 
9206
   
 
9207
  return (DialoG) p;
 
9208
    
 
9209
}
 
9210
 
 
9211
 
 
9212
static Boolean DoesIDListMeetStringConstraint (SeqIdPtr sip, StringConstraintPtr string_constraint)
 
9213
{
 
9214
  Char       id [41];
 
9215
  SeqIdPtr   tmp;
 
9216
 
 
9217
  if (sip == NULL) 
 
9218
  {
 
9219
    return FALSE;
 
9220
  }
 
9221
  if (string_constraint == NULL)
 
9222
  {
 
9223
    return TRUE;
 
9224
  }
 
9225
  
 
9226
  while (sip != NULL)
 
9227
  {
 
9228
    tmp = sip->next;
 
9229
    sip->next = NULL;
 
9230
    id [0] = '\0';
 
9231
    SeqIdWrite (sip, id, PRINTID_FASTA_LONG, sizeof (id) - 1);
 
9232
    sip->next = tmp;
 
9233
    if (DoesStringMatchConstraint (id, string_constraint))
 
9234
    {
 
9235
      if (string_constraint->not_present)
 
9236
      {
 
9237
        return FALSE;
 
9238
      }
 
9239
      else
 
9240
      {
 
9241
        return TRUE;
 
9242
      }
 
9243
    }
 
9244
    sip = sip->next;
 
9245
  }
 
9246
  if (string_constraint->not_present)
 
9247
  {
 
9248
    return TRUE;
 
9249
  }
 
9250
  else
 
9251
  {
 
9252
    return FALSE;
 
9253
  }
 
9254
}
 
9255
 
 
9256
 
 
9257
static Boolean DoesSequenceMatchSequenceConstraint (BioseqPtr bsp, SequenceConstraintPtr scp)
 
9258
{
 
9259
  SeqDescrPtr       sdp;
 
9260
  SeqMgrDescContext dcontext;
 
9261
  
 
9262
  if (bsp == NULL) return FALSE;
 
9263
  if (scp == NULL) return TRUE;
 
9264
  if (!scp->nucs_ok && ISA_na (bsp->mol)) return FALSE;
 
9265
  if (!scp->prots_ok && ISA_aa (bsp->mol)) return FALSE;
 
9266
  switch (scp->other_constraint_type)
 
9267
  {
 
9268
    case SEQ_CONSTRAINT_ANY:
 
9269
      return TRUE;
 
9270
      break;
 
9271
    case SEQ_CONSTRAINT_SOURCE:
 
9272
      sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &dcontext);
 
9273
      if (sdp != NULL)
 
9274
      {
 
9275
        return DoesOneSourceMatchConstraint(sdp->data.ptrvalue, scp->source_constraint);
 
9276
      }
 
9277
      break;
 
9278
    case SEQ_CONSTRAINT_FEATURE_TEXT:
 
9279
      return DoBioseqFeaturesMatchSequenceConstraint (bsp, scp->feature_list, scp->string_constraint);
 
9280
      break;
 
9281
    case SEQ_CONSTRAINT_ID:
 
9282
      return DoesIDListMeetStringConstraint(bsp->id, scp->string_constraint);
 
9283
      break;
 
9284
  }
 
9285
  return FALSE; 
 
9286
}
 
9287
 
8942
9288
typedef struct molinfoedit {
8943
9289
  DESCRIPTOR_FORM_BLOCK
8944
9290
  SeqEntryPtr     sep;
8945
9291
  MolInfoBlock    from;
8946
9292
  MolInfoBlock    to;
8947
 
  GrouP           constraint;
8948
 
  Boolean         nucsOK;
8949
 
  Boolean         protsOK;
 
9293
  DialoG          sequence_constraint;
 
9294
  SequenceConstraintPtr scp;
8950
9295
} MolInfoEdit, PNTR MolInfoEditPtr;
8951
9296
 
8952
9297
static CharPtr  labels [] = {
9025
9370
  if (IS_Bioseq (sep)) {
9026
9371
 
9027
9372
    bsp = (BioseqPtr) sep->data.ptrvalue;
9028
 
    if ((ISA_na (bsp->mol) && miep->nucsOK) ||
9029
 
        (ISA_aa (bsp->mol) && miep->protsOK)) {
 
9373
    if (DoesSequenceMatchSequenceConstraint (bsp, miep->scp)) {
9030
9374
      if ((Uint1)GetValNodePopup (miep->from.molPopup,
9031
9375
                                  miep->from.mol_values) == bsp->mol
9032
9376
        || GetValue (miep->from.molPopup) == 1)
9071
9415
  } else if (IS_Bioseq_set (sep)) {
9072
9416
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
9073
9417
    if (bssp->_class == 2 || bssp->_class == 4) {
9074
 
      if (! miep->nucsOK) return;
 
9418
      if (miep->scp != NULL && ! miep->scp->nucs_ok) return;
9075
9419
    }
9076
9420
    sdp = bssp->descr;
9077
9421
  } else {
9120
9464
 
9121
9465
{
9122
9466
  MolInfoEditPtr  miep;
9123
 
  Int2            val;
9124
9467
 
9125
9468
  miep = (MolInfoEditPtr) GetObjectExtra (b);
9126
9469
  if (miep == NULL) return;
9127
9470
  Hide (miep->form);
9128
9471
  WatchCursor ();
9129
9472
  Update ();
9130
 
  val = GetValue (miep->constraint);
9131
 
  miep->nucsOK = (Boolean) (val == 1 || val == 2);
9132
 
  miep->protsOK = (Boolean) (val == 1 || val == 3);
 
9473
  
 
9474
  miep->scp = DialogToPointer (miep->sequence_constraint);
 
9475
  
9133
9476
  SeqEntryExplore (miep->sep, (Pointer) miep, EditMolInfoCallback);
9134
9477
  FreeMolInfoBlockData (&(miep->from));
9135
9478
  FreeMolInfoBlockData (&(miep->to));
 
9479
  miep->scp = SequenceConstraintFree (miep->scp);
9136
9480
  ArrowCursor ();
9137
9481
  Update ();
9138
9482
  ObjMgrSetDirtyFlag (miep->input_entityID, TRUE);
9148
9492
  GrouP           c;
9149
9493
  GrouP           g;
9150
9494
  GrouP           h;
9151
 
  GrouP           k;
9152
9495
  MolInfoEditPtr  miep;
9153
9496
  SeqEntryPtr     sep;
9154
9497
  WindoW          w;
9171
9514
  miep->sep = sep;
9172
9515
  miep->input_entityID = bfp->input_entityID;
9173
9516
 
9174
 
  k = HiddenGroup (w, 2, 0, NULL);
9175
 
  StaticPrompt (k, "Constraint", 0, stdLineHeight, programFont, 'l');
9176
 
  miep->constraint = HiddenGroup (k, 4, 0, NULL);
9177
 
  RadioButton (miep->constraint, "All Sequences");
9178
 
  RadioButton (miep->constraint, "Nucleotides");
9179
 
  RadioButton (miep->constraint, "Proteins");
9180
 
  SetValue (miep->constraint, 2);
9181
 
 
9182
9517
  g = HiddenGroup (w, 2, 0, NULL);
9183
9518
  h = HiddenGroup (g, 0, 2, NULL);
9184
9519
  StaticPrompt (h, "From", 0, 0, programFont, 'c');
9187
9522
  StaticPrompt (h, "To", 0, 0, programFont, 'c');
9188
9523
  CreateMolInfoBlock (&miep->to, h, TRUE);
9189
9524
 
 
9525
  miep->sequence_constraint = SequenceConstraintDialog (w);
 
9526
 
9190
9527
  c = HiddenGroup (w, 2, 0, NULL);
9191
9528
  b = DefaultButton (c, "Accept", DoProcessEditMolInfo);
9192
9529
  SetObjectExtra (b, miep, NULL);
9193
9530
  PushButton (c, "Cancel", StdCancelButtonProc);
9194
 
  AlignObjects (ALIGN_CENTER, (HANDLE) k, (HANDLE) g, (HANDLE) c, NULL);
 
9531
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) miep->sequence_constraint, (HANDLE) c, NULL);
9195
9532
  RealizeWindow (w);
9196
9533
  Show (w);
9197
9534
  Update ();
9289
9626
  if (SeqEntryGetSeqDescr (sep, Seq_descr_molinfo, NULL) != NULL) return;
9290
9627
  if (IS_Bioseq (sep)) {
9291
9628
    bsp = (BioseqPtr) sep->data.ptrvalue;
9292
 
    if ((ISA_na (bsp->mol) && miep->nucsOK) ||
9293
 
        (ISA_aa (bsp->mol) && miep->protsOK)) {
 
9629
    if (DoesSequenceMatchSequenceConstraint(bsp, miep->scp)) {
9294
9630
      if ( GetValue (miep->to.molPopup) != 1)
9295
9631
      {
9296
9632
        bsp->mol = (Uint1) GetValNodePopup (miep->to.molPopup,
9310
9646
  } else if (IS_Bioseq_set (sep)) {
9311
9647
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
9312
9648
    if (bssp->_class == 2 || bssp->_class == 4) {
9313
 
      if (! miep->nucsOK) return;
 
9649
      if (miep->scp != NULL && ! miep->scp->nucs_ok) return;
9314
9650
    }
9315
9651
  } else return;
9316
9652
  mip = MolInfoNew ();
9340
9676
 
9341
9677
{
9342
9678
  MolInfoEditPtr  miep;
9343
 
  Int2            val;
9344
9679
 
9345
9680
  miep = (MolInfoEditPtr) GetObjectExtra (b);
9346
9681
  if (miep == NULL) return;
9347
9682
  Hide (miep->form);
9348
9683
  WatchCursor ();
9349
9684
  Update ();
9350
 
  val = GetValue (miep->constraint);
9351
 
  miep->nucsOK = (Boolean) (val == 1);
9352
 
  miep->protsOK = (Boolean) (val == 2);
 
9685
  miep->scp = DialogToPointer (miep->sequence_constraint);
9353
9686
  DoApplyMolInfo (miep->sep, miep);
9354
9687
  FreeMolInfoBlockData (&miep->to);
 
9688
  miep->scp = SequenceConstraintFree (miep->scp);
9355
9689
  ArrowCursor ();
9356
9690
  Update ();
9357
9691
  ObjMgrSetDirtyFlag (miep->input_entityID, TRUE);
9367
9701
  GrouP           c;
9368
9702
  GrouP           g;
9369
9703
  GrouP           h;
9370
 
  GrouP           k;
9371
9704
  MolInfoEditPtr  miep;
9372
9705
  SeqEntryPtr     sep;
9373
9706
  WindoW          w;
9390
9723
  miep->sep = sep;
9391
9724
  miep->input_entityID = bfp->input_entityID;
9392
9725
 
9393
 
  k = HiddenGroup (w, 2, 0, NULL);
9394
 
  StaticPrompt (k, "Constraint", 0, stdLineHeight, programFont, 'l');
9395
 
  miep->constraint = HiddenGroup (k, 4, 0, NULL);
9396
 
  RadioButton (miep->constraint, "Nucleotides");
9397
 
  RadioButton (miep->constraint, "Proteins");
9398
 
  SetValue (miep->constraint, 0);
9399
 
 
9400
9726
  g = HiddenGroup (w, 2, 0, NULL);
9401
9727
  h = HiddenGroup (g, 0, 2, NULL);
9402
9728
  CreateMolInfoBlock (&miep->to, h, TRUE);
9403
9729
 
 
9730
  miep->sequence_constraint = SequenceConstraintDialog (w);
 
9731
 
9404
9732
  c = HiddenGroup (w, 2, 0, NULL);
9405
9733
  b = DefaultButton (c, "Accept", DoProcessApplyMolInfo);
9406
9734
  SetObjectExtra (b, miep, NULL);
9407
9735
  PushButton (c, "Cancel", StdCancelButtonProc);
9408
 
  AlignObjects (ALIGN_CENTER, (HANDLE) k, (HANDLE) g, (HANDLE) c, NULL);
 
9736
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) miep->sequence_constraint, (HANDLE) c, NULL);
9409
9737
  RealizeWindow (w);
9410
9738
  Show (w);
9411
9739
  Update ();
9752
10080
  Update ();
9753
10081
}
9754
10082
 
9755
 
static void AddGenePseudoConstraint (IteM i)
9756
 
{
9757
 
  GenePseudoConstraint (i, TRUE);       
9758
 
}
9759
 
 
9760
10083
static void ClearGenePseudoConstraint (IteM i)
9761
10084
{
9762
10085
  GenePseudoConstraint (i, FALSE);      
11878
12201
  OrgModPtr    omp;
11879
12202
  OrgNamePtr   onp;
11880
12203
  OrgRefPtr    orp;
11881
 
  CharPtr      str;
 
12204
  CharPtr      str, cp_end;
11882
12205
  ValNodePtr   vnp;
11883
12206
 
11884
12207
  if (biop == NULL) return;
11891
12214
      str = StringISearch (omp->subname, "ATCC");
11892
12215
      if (str != NULL)
11893
12216
      {
 
12217
        /* skip over ATCC */
11894
12218
        str += 4;
 
12219
        /* skip over colon and whitespace */
11895
12220
        ch = *str;
11896
12221
        while (IS_WHITESP (ch) || ch == ':') {
11897
12222
          str++;
11898
12223
          ch = *str;
11899
12224
        }
11900
 
        if (! StringHasNoText (str)) {
 
12225
        
 
12226
        cp_end = StringChr (str, ';');
 
12227
        if (cp_end != NULL)
 
12228
        {
 
12229
          *cp_end = 0;
 
12230
        }
 
12231
        if (! StringHasNoText (str)) {          
11901
12232
          for (vnp = orp->db; vnp != NULL; vnp = vnp->next) {
11902
12233
            dbt = (DbtagPtr) vnp->data.ptrvalue;
11903
12234
            if (dbt != NULL && StringICmp (dbt->db, "ATCC") == 0) {
11916
12247
          dbt->tag = oip;
11917
12248
          ValNodeAddPointer (&(orp->db), 0, (Pointer) dbt);
11918
12249
        }
 
12250
        if (cp_end != NULL)
 
12251
        {
 
12252
          *cp_end = ';';
 
12253
        }
11919
12254
      }
11920
12255
    }
11921
12256
  }
14080
14415
  
14081
14416
  if (lip != NULL && lip->fp != NULL && slp != NULL)
14082
14417
  {
14083
 
    loc_str = SeqLocPrint(slp);
 
14418
    loc_str = SeqLocPrintUseBestID(slp);
14084
14419
    fprintf (lip->fp, "%s\n", loc_str);
14085
14420
                MemFree(loc_str);
14086
14421
                lip->data_in_log = TRUE;
14088
14423
    
14089
14424
}
14090
14425
 
 
14426
 
14091
14427
static void BioseqTrimNAndLog (BioseqPtr bsp, Pointer userdata)
14092
14428
{
14093
14429
  TrimNAndLogPtr tnalp;
14095
14431
  SeqLocPtr      slp1 = NULL,
14096
14432
                 slp2 = NULL;
14097
14433
  CharPtr       str;
14098
 
  Int4          j,
14099
 
                lens;
 
14434
  Int4          j, lens;
14100
14435
    
14101
14436
  tnalp = (TrimNAndLogPtr) userdata;
14102
14437
  if (bsp == NULL || ! ISA_na (bsp->mol) || tnalp == NULL)
14118
14453
     {
14119
14454
        slp1 = SeqLocIntNew (j+1, lens-1, Seq_strand_plus, sip);
14120
14455
        SeqDeleteByLoc (slp1, TRUE, FALSE);
 
14456
        TrimQualityScores (bsp, lens - 1 - j, FALSE);        
14121
14457
     }
14122
14458
     j=0;
14123
14459
     while (j<lens) {
14128
14464
     if (j>0) {
14129
14465
        slp2 = SeqLocIntNew (0, j-1, Seq_strand_plus, sip);
14130
14466
        SeqDeleteByLoc (slp2, TRUE, FALSE);
 
14467
        TrimQualityScores (bsp, j, TRUE);        
14131
14468
     }
14132
14469
     if (slp1!=NULL) {
14133
14470
        LogTrimmedLocation (tnalp->lip, slp1);
16567
16904
 { "bac", "BAC" },
16568
16905
 { "caenorhabditis elegans", "Caenorhabditis elegans" },
16569
16906
 { "cdna", "cDNA" },
 
16907
 { "cdnas", "cDNAs" },
16570
16908
 { "coi", "COI" },
16571
16909
 { "coii", "COII" },
16572
16910
 { "danio rerio", "Danio rerio" },
16674
17012
 { "But", "but" },
16675
17013
 { "By", "by" },
16676
17014
 { "In", "in" },
16677
 
 { "Is", "in" },
 
17015
 { "Is", "is" },
16678
17016
 { "Of", "of" },
16679
17017
 { "Or", "or" },
16680
17018
 { "The", "the" },
16739
17077
    FixAbbreviationsInElement (pEl);
16740
17078
}
16741
17079
 
16742
 
static void FixCapitalizationInTitle (CharPtr PNTR pTitle, Boolean first_is_upper)
 
17080
 
 
17081
static void FixOrgNamesInString (CharPtr str, ValNodePtr org_names)
 
17082
{
 
17083
  ValNodePtr vnp;
 
17084
  CharPtr    cp, taxname;
 
17085
  Int4       taxname_len;
 
17086
  
 
17087
  if (StringHasNoText (str) || org_names == NULL) return;
 
17088
  for (vnp = org_names; vnp != NULL; vnp = vnp->next)
 
17089
  {
 
17090
    taxname = (CharPtr) org_names->data.ptrvalue;
 
17091
    taxname_len = StringLen (taxname);
 
17092
    cp = StringISearch (str, taxname);
 
17093
    while (cp != NULL)
 
17094
    {
 
17095
      StringNCpy (cp, taxname, taxname_len);
 
17096
      cp = StringISearch (cp + taxname_len, taxname);
 
17097
    }
 
17098
  }
 
17099
}
 
17100
 
 
17101
 
 
17102
extern void ResetCapitalization (Boolean first_is_upper, CharPtr pString)
16743
17103
{
16744
17104
  CharPtr pCh;
16745
17105
  Boolean was_digit = FALSE;
16746
17106
 
16747
 
  if (pTitle == NULL) return;
16748
 
  pCh = *pTitle;
 
17107
  pCh = pString;
16749
17108
  if (pCh == NULL) return;
16750
17109
  if (*pCh == '\0') return;
16751
17110
  
16785
17144
      *pCh = tolower (*pCh);
16786
17145
    }
16787
17146
    pCh++;
16788
 
  }
 
17147
  }  
 
17148
}
 
17149
 
 
17150
 
 
17151
static void 
 
17152
FixCapitalizationInTitle 
 
17153
(CharPtr PNTR pTitle,
 
17154
 Boolean      first_is_upper,
 
17155
 ValNodePtr   org_names)
 
17156
{
 
17157
  if (pTitle == NULL) return;
 
17158
  ResetCapitalization (first_is_upper, *pTitle);
16789
17159
  FixAbbreviationsInElement (pTitle);
 
17160
  FixOrgNamesInString (*pTitle, org_names);
16790
17161
}
16791
17162
 
16792
17163
static void FixCapitalizationInAuthor (AuthorPtr pAuthor)
16895
17266
{
16896
17267
  Int4                iType;
16897
17268
  StringConstraintPtr author_scp;
 
17269
  ValNodePtr          org_names;
16898
17270
} FixPubdescData, PNTR FixPubdescPtr;
16899
17271
 
16900
17272
static void FixPubdesc (PubdescPtr pdp, Pointer userdata)
16972
17344
    }
16973
17345
 
16974
17346
    if(iType & FIX_PUB_TITLE_CAPITALIZATION ) {
16975
 
      FixCapitalizationInTitle (title, TRUE);
 
17347
      FixCapitalizationInTitle (title, TRUE, fpp->org_names);
16976
17348
    }
16977
17349
 
16978
17350
    if(alp == NULL) continue;
17021
17393
  }
17022
17394
}
17023
17395
 
 
17396
 
 
17397
static void GetOrgNamesInRecordCallback (BioSourcePtr biop, Pointer userdata)
 
17398
{
 
17399
  ValNodePtr PNTR org_names;
 
17400
  
 
17401
  if (biop == NULL || biop->org == NULL || StringHasNoText (biop->org->taxname)
 
17402
      || userdata == NULL)
 
17403
  {
 
17404
    return;
 
17405
  }
 
17406
  
 
17407
  org_names = (ValNodePtr PNTR) userdata;
 
17408
  
 
17409
  ValNodeAddPointer (org_names, 0, biop->org->taxname);
 
17410
}
 
17411
 
 
17412
 
17024
17413
/* This function is used to apply fixes to citations */
17025
17414
static void FixPubs (Uint2 entityID, Int4 iType, StringConstraintPtr author_scp)
17026
17415
{
17046
17435
  fpd.iType = iType;
17047
17436
  fpd.author_scp = author_scp;
17048
17437
  
 
17438
  fpd.org_names = NULL;
 
17439
  if (iType & FIX_PUB_TITLE_CAPITALIZATION)
 
17440
  {
 
17441
    VisitBioSourcesInSep (sep, &(fpd.org_names), GetOrgNamesInRecordCallback);
 
17442
  }
 
17443
  
17049
17444
  if(sel == NULL)
17050
17445
  {
17051
17446
    VisitPubdescsInSep (sep, (Pointer)&fpd, FixPubdesc);
17079
17474
      sel = sel->next;      
17080
17475
    }
17081
17476
  }
 
17477
  
 
17478
  fpd.org_names = ValNodeFree (fpd.org_names);
17082
17479
 
17083
17480
  ObjMgrSetDirtyFlag (entityID, TRUE);
17084
17481
  ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
17271
17668
      for (vnp = prp->name; vnp != NULL; vnp = vnp->next)
17272
17669
      {
17273
17670
        product_name = (CharPtr)(vnp->data.ptrvalue);
17274
 
        FixCapitalizationInTitle (&product_name, FALSE);
 
17671
        FixCapitalizationInTitle (&product_name, FALSE, NULL);
17275
17672
        vnp->data.ptrvalue = product_name;
17276
17673
      }
17277
17674
    }
17282
17679
    if (rrp != NULL && rrp->ext.choice == 1)
17283
17680
    {
17284
17681
      product_name = (CharPtr)(rrp->ext.value.ptrvalue);
17285
 
      FixCapitalizationInTitle (&product_name, FALSE);
 
17682
      FixCapitalizationInTitle (&product_name, FALSE, NULL);
17286
17683
      rrp->ext.value.ptrvalue = product_name;
17287
17684
    }
17288
17685
  }
17383
17780
 
17384
17781
static void FixDeltaSeqDataLen (IteM i)
17385
17782
{
17386
 
  BaseFormPtr       bfp;
17387
 
  SeqEntryPtr       sep;
 
17783
  BaseFormPtr  bfp;
 
17784
  SeqEntryPtr  sep;
17388
17785
  
17389
17786
#ifdef WIN_MAC
17390
17787
  bfp = currentFormDataPtr;
17400
17797
  Update ();      
17401
17798
}
17402
17799
 
 
17800
static void InstantiateGapFeatCallback (BioseqPtr bsp, Pointer userdata)
 
17801
 
 
17802
{
 
17803
  Char        buf [32];
 
17804
  Int4        currpos = 0;
 
17805
  IntFuzzPtr  fuzz;
 
17806
  ImpFeatPtr  ifp;
 
17807
  SeqLitPtr   litp;
 
17808
  SeqFeatPtr  sfp;
 
17809
  SeqIdPtr    sip;
 
17810
  SeqLocPtr   slp;
 
17811
  ValNodePtr  vnp;
 
17812
 
 
17813
  if (bsp == NULL || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4) return;
 
17814
  sip = SeqIdFindBest (bsp->id, 0);
 
17815
  if (sip == NULL) return;
 
17816
  /* suppress on far delta contigs for now */
 
17817
  if (! DeltaLitOnly (bsp)) return;
 
17818
 
 
17819
  for (vnp = (ValNodePtr)(bsp->seq_ext); vnp != NULL; vnp = vnp->next) {
 
17820
    if (vnp->choice == 1) {
 
17821
      slp = (SeqLocPtr) vnp->data.ptrvalue;
 
17822
      if (slp == NULL) continue;
 
17823
      currpos += SeqLocLen (slp);
 
17824
    }
 
17825
    if (vnp->choice == 2) {
 
17826
      litp = (SeqLitPtr) vnp->data.ptrvalue;
 
17827
      if (litp == NULL) continue;
 
17828
      if (litp->seq_data == NULL && litp->length > 0) {
 
17829
        ifp = ImpFeatNew ();
 
17830
        if (ifp == NULL) continue;
 
17831
        ifp->key = StringSave ("gap");
 
17832
        fuzz = litp->fuzz;
 
17833
        sfp = CreateNewFeatureOnBioseq (bsp, SEQFEAT_IMP, NULL);
 
17834
        if (sfp == NULL) continue;
 
17835
        sfp->data.choice = SEQFEAT_IMP;
 
17836
        sfp->data.value.ptrvalue = (Pointer) ifp;
 
17837
        if (fuzz != NULL && fuzz->choice == 4 && fuzz->a == 0) {
 
17838
          AddQualifierToFeature (sfp, "estimated_length", "unknown");
 
17839
          sfp->location = SeqLocFree (sfp->location);
 
17840
          sfp->location = AddIntervalToLocation (NULL, sip, currpos, currpos + litp->length - 1, FALSE, FALSE);
 
17841
        } else {
 
17842
          sprintf (buf, "%ld", (long) litp->length);
 
17843
          AddQualifierToFeature (sfp, "estimated_length", buf);
 
17844
          sfp->location = SeqLocFree (sfp->location);
 
17845
          sfp->location = AddIntervalToLocation (NULL, sip, currpos, currpos + litp->length - 1, FALSE, FALSE);
 
17846
        }
 
17847
      }
 
17848
      currpos += litp->length;
 
17849
    }
 
17850
  }
 
17851
}
 
17852
 
 
17853
static void InstantiateGapFeatures (IteM i)
 
17854
 
 
17855
{
 
17856
  BaseFormPtr  bfp;
 
17857
  SeqEntryPtr  sep;
 
17858
  
 
17859
#ifdef WIN_MAC
 
17860
  bfp = currentFormDataPtr;
 
17861
#else
 
17862
  bfp = GetObjectExtra (i);
 
17863
#endif
 
17864
  if (bfp == NULL) return;
 
17865
  
 
17866
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
17867
  VisitBioseqsInSep (sep, NULL, InstantiateGapFeatCallback);
 
17868
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
17869
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
17870
  Update ();      
 
17871
}
 
17872
 
 
17873
static void RemoveGapFeatCallback (SeqFeatPtr sfp, Pointer userdata)
 
17874
 
 
17875
{
 
17876
  GBQualPtr  gbq;
 
17877
 
 
17878
  if (sfp == NULL) return;
 
17879
  if (sfp->idx.subtype != FEATDEF_gap) return;
 
17880
  if (StringDoesHaveText (sfp->comment)) return;
 
17881
  for (gbq = sfp->qual; gbq != NULL; gbq = gbq->next) {
 
17882
    if (StringICmp (gbq->qual, "estimated_length") != 0) return;
 
17883
  }
 
17884
  sfp->idx.deleteme = TRUE;
 
17885
}
 
17886
 
 
17887
static void RemoveUnnecessaryGapFeatures (IteM i)
 
17888
 
 
17889
{
 
17890
  BaseFormPtr  bfp;
 
17891
  SeqEntryPtr  sep;
 
17892
  
 
17893
#ifdef WIN_MAC
 
17894
  bfp = currentFormDataPtr;
 
17895
#else
 
17896
  bfp = GetObjectExtra (i);
 
17897
#endif
 
17898
  if (bfp == NULL) return;
 
17899
  
 
17900
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
17901
  VisitFeaturesInSep (sep, NULL, RemoveGapFeatCallback);
 
17902
 
 
17903
  ObjMgrSelect (0, 0, 0, 0, NULL);
 
17904
 
 
17905
  DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
 
17906
 
 
17907
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
17908
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
17909
  Update ();      
 
17910
}
 
17911
 
 
17912
 
 
17913
static void RenormalizeNucProtSetsMenuItem (IteM i)
 
17914
{
 
17915
  BaseFormPtr  bfp;
 
17916
  SeqEntryPtr  sep;
 
17917
 
 
17918
  /* Get the current data */
 
17919
 
 
17920
#ifdef WIN_MAC
 
17921
  bfp = currentFormDataPtr;
 
17922
#else
 
17923
  bfp = GetObjectExtra (i);
 
17924
#endif
 
17925
 
 
17926
  if (bfp == NULL)
 
17927
    return;
 
17928
 
 
17929
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
17930
  if (sep == NULL) return;
 
17931
  WatchCursor();
 
17932
  Update();
 
17933
  RenormalizeNucProtSets (sep, TRUE);           
 
17934
  
 
17935
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
17936
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
17937
  ArrowCursor ();
 
17938
  Update ();
 
17939
 
 
17940
  /* Return successfully */
 
17941
 
 
17942
  return;
 
17943
}
 
17944
 
 
17945
 
17403
17946
extern void LookupAllPubs (IteM i);
17404
17947
extern void ResolveExistingLocalIDs (IteM i);
17405
17948
extern void PromoteAlignsToBestIDProc (IteM i);
17425
17968
static void NewAligmentViewer (IteM i)
17426
17969
{
17427
17970
  BaseFormPtr  bfp;
17428
 
  ForM         f;
17429
17971
  BioseqPtr    bsp;
17430
 
  Int2         top;
17431
17972
  ValNodePtr   seq_annot_list;
17432
17973
  SeqAnnotPtr  sap;
17433
17974
  SeqAlignPtr  salp = NULL;
17459
18000
    return;
17460
18001
  }
17461
18002
  
 
18003
  OpenNewAlignmentEditor (salp, bfp->input_entityID);
 
18004
 
 
18005
}
 
18006
 
 
18007
static void ShowDiscrepancyReport (IteM i)
 
18008
{
 
18009
  BaseFormPtr  bfp;
17462
18010
#ifdef WIN_MAC
17463
 
  top = 53;
 
18011
  bfp = currentFormDataPtr;
17464
18012
#else
17465
 
  top = 33;
 
18013
  bfp = GetObjectExtra (i);
17466
18014
#endif
17467
18015
 
17468
 
  f = CreateAlnEditorWindow (33, top, "Alignment Assistant", salp, bfp->input_entityID);
17469
 
 
17470
 
  if (f != NULL)
17471
 
  {
17472
 
     Show (f);
17473
 
     Update ();
17474
 
     Select (f);
17475
 
  }
 
18016
  if (bfp == NULL) return;
 
18017
  
 
18018
  CreateDiscrepancyReportWindow (bfp);
17476
18019
}
17477
18020
 
17478
18021
static void TestTax3 (IteM i, Int4 taxid, CharPtr name)
17539
18082
  TestTax3 (i, 0, "Escherichia coli");
17540
18083
}
17541
18084
 
 
18085
static void MakeFarProtRefXref (SeqFeatPtr sfp)
 
18086
 
 
18087
{
 
18088
  BioseqPtr          bsp;
 
18089
  Uint2              entityID;
 
18090
  SeqMgrFeatContext  pcontext;
 
18091
  SeqFeatPtr         prot;
 
18092
  ProtRefPtr         prp;
 
18093
  SeqIdPtr           sip;
 
18094
  SeqFeatXrefPtr     xref;
 
18095
 
 
18096
  for (xref = sfp->xref; xref != NULL; xref = xref->next) {
 
18097
    if (xref->data.choice == SEQFEAT_PROT) return;
 
18098
  }
 
18099
 
 
18100
  sip = SeqLocIdForProduct (sfp->product);
 
18101
  if (sip == NULL) return;
 
18102
  bsp = BioseqLockById (sip);
 
18103
  if (bsp == NULL) return;
 
18104
 
 
18105
  entityID = ObjMgrGetEntityIDForPointer (bsp);
 
18106
  if (entityID != 0 && SeqMgrFeaturesAreIndexed (entityID) == 0) {
 
18107
    SeqMgrIndexFeatures (entityID, NULL);
 
18108
  }
 
18109
 
 
18110
  prot = SeqMgrGetBestProteinFeature (bsp, &pcontext);
 
18111
  if (prot != NULL && prot->data.choice == SEQFEAT_PROT) {
 
18112
    prp = (ProtRefPtr) prot->data.value.ptrvalue;
 
18113
    if (prp != NULL) {
 
18114
      xref = SeqFeatXrefNew ();
 
18115
      if (xref != NULL) {
 
18116
        xref->data.choice = SEQFEAT_PROT;
 
18117
        xref->data.value.ptrvalue = AsnIoMemCopy ((Pointer) prp,
 
18118
                                                  (AsnReadFunc) ProtRefAsnRead,
 
18119
                                                  (AsnWriteFunc) ProtRefAsnWrite);
 
18120
        xref->next = sfp->xref;
 
18121
        sfp->xref = xref;
 
18122
      }
 
18123
    }
 
18124
  }
 
18125
 
 
18126
  BioseqUnlock (bsp);
 
18127
}
 
18128
 
 
18129
static void MakeRedundantGenomicProtXref (
 
18130
  IteM i
 
18131
)
 
18132
 
 
18133
{
 
18134
  BaseFormPtr        bfp;
 
18135
  BioseqPtr          bsp;
 
18136
  SeqMgrFeatContext  fcontext;
 
18137
  SeqEntryPtr        sep;
 
18138
  SeqFeatPtr         sfp;
 
18139
 
 
18140
#ifdef WIN_MAC
 
18141
  bfp = currentFormDataPtr;
 
18142
#else
 
18143
  bfp = GetObjectExtra (i);
 
18144
#endif
 
18145
  if (bfp == NULL) return;
 
18146
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
18147
  if (sep == NULL) return;
 
18148
 
 
18149
  /* find genomic sequence */
 
18150
  bsp = FindNucBioseq (sep);
 
18151
  if (bsp != NULL) {
 
18152
    sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_CDREGION, 0, &fcontext);
 
18153
    while (sfp != NULL) {
 
18154
      MakeFarProtRefXref (sfp);
 
18155
      sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_CDREGION, 0, &fcontext);
 
18156
    }
 
18157
  }
 
18158
 
 
18159
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
18160
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
18161
}
 
18162
 
17542
18163
extern void SetupSpecialMenu (MenU m, BaseFormPtr bfp)
17543
18164
 
17544
18165
{
17545
18166
  IteM  i;
17546
18167
  MenU  s;
17547
 
  MenU  x;
 
18168
  MenU  x, y, z;
17548
18169
 
17549
18170
  s = SubMenu (m, "Def Line/ D");
17550
18171
  x = SubMenu (s, "Automatic Def Line");
17590
18211
  s = SubMenu (m, "Organism/ G");
17591
18212
  i = CommandItem (s, "Parse Text", ParseDefLineToSourceQual);
17592
18213
  SetObjectExtra (i, bfp, NULL);
17593
 
  i = CommandItem (s, "Parse File to Source", ParseFileToSource);
17594
 
  SetObjectExtra (i, bfp, NULL);
17595
18214
  SeparatorItem (s);
17596
18215
  i = CommandItem (s, "Parse ATCC Strain to Xref", AtccStrainToXref);
17597
18216
  SetObjectExtra (i, bfp, NULL);
17598
18217
  SeparatorItem (s);
17599
 
  i = CommandItem (s, "Append Modifier to Organism", AddModToOrg);
17600
 
  SetObjectExtra (i, bfp, NULL);
17601
 
  SeparatorItem (s);
17602
18218
  i = CommandItem (s, "Trim Organism Name", TrimOrganismName);
17603
18219
  SetObjectExtra (i, bfp, NULL);
 
18220
  i = CommandItem (s, "Genus-Species Fixup", GenSpecTaxonFixup);
 
18221
  SetObjectExtra (i, bfp, NULL);
17604
18222
  SeparatorItem (s);
17605
18223
  i = CommandItem (s, "Prefix Authority with Organism", PrefixAuthorityWithOrganism);
17606
18224
  SetObjectExtra (i, bfp, NULL);
 
18225
  i = CommandItem (s, "Append Modifier to Organism", AddModToOrg);
 
18226
  SetObjectExtra (i, bfp, NULL);
17607
18227
  i = CommandItem (s, "Parse Trinomial into Subspecies", ParseTrinomial);
17608
18228
  SetObjectExtra (i, bfp, NULL);
17609
18229
  SeparatorItem (s);
17610
 
  i = CommandItem (s, "Genus-Species Fixup", GenSpecTaxonFixup);
17611
 
  SetObjectExtra (i, bfp, NULL);
17612
 
  SeparatorItem (s);
17613
 
  i = CommandItem (s, "Country Fixup", CountryLookup);
17614
 
  SetObjectExtra (i, bfp, NULL);
17615
 
  SeparatorItem (s);
17616
 
  i = CommandItem (s, "Set Source Focus", SetSourceFocus);
17617
 
  SetObjectExtra (i, bfp, NULL);
17618
 
  i = CommandItem (s, "Clear Source Focus", ClearSourceFocus);
 
18230
  x = SubMenu (s, "Country Fixup");
 
18231
  i = CommandItem (x, "Do Not Fix Capitalization After Colon", CountryLookupWithoutCapFix);
 
18232
  SetObjectExtra (i, bfp, NULL);
 
18233
  i = CommandItem (x, "Fix Capitalization After Colon", CountryLookupWithCapFix);
 
18234
  SetObjectExtra (i, bfp, NULL);
 
18235
  SeparatorItem (s);
 
18236
  x = SubMenu (s, "Parse CollectionDate formats");
 
18237
  i = CommandItem (x, "Month First", ParseCollectionDateMonthFirst);
 
18238
  SetObjectExtra (i, bfp, NULL);
 
18239
  i = CommandItem (x, "Day First", ParseCollectionDateDayFirst);
 
18240
  SetObjectExtra (i, bfp, NULL);
 
18241
    SeparatorItem (s);
 
18242
  x = SubMenu (s, "Source Focus");
 
18243
  i = CommandItem (x, "Set", SetSourceFocus);
 
18244
  SetObjectExtra (i, bfp, NULL);
 
18245
  i = CommandItem (x, "Clear", ClearSourceFocus);
17619
18246
  SetObjectExtra (i, bfp, NULL);
17620
18247
  SeparatorItem (s);
17621
18248
  i = CommandItem (s, "Consolidate Organism Notes", ConsolidateOrganismNotes);
17626
18253
  i = CommandItem (x, "Without semicolons", ConsolidateLikeModifiersWithoutSemicolons);
17627
18254
  SetObjectExtra (i, bfp, NULL);
17628
18255
  SeparatorItem (s);
17629
 
  i = CommandItem (s, "Load Organism Modifiers from File", LoadOrganismModifierTable);
17630
 
  SetObjectExtra (i, bfp, NULL);
17631
 
  i = CommandItem (s, "Export Organism Modifiers to File", ExportOrganismTable);
17632
 
  SetObjectExtra (i, bfp, NULL);
17633
 
  i = CommandItem (s, "Export Last Lineage Table", ExportLastLineage);
17634
 
  SetObjectExtra (i, bfp, NULL);
 
18256
  x = SubMenu(s, "Parse Organism Modifiers");
 
18257
  i = CommandItem (x, "Load From File", LoadOrganismModifierTable);
 
18258
  SetObjectExtra (i, bfp, NULL);
 
18259
  i = CommandItem (x, "Export To File", ExportOrganismTable);
 
18260
  SetObjectExtra (i, bfp, NULL);
 
18261
  i = CommandItem (x, "Export Last Lineage Table", ExportLastLineage);
 
18262
  SetObjectExtra (i, bfp, NULL);
 
18263
  i = CommandItem (s, "Parse File to Source", ParseFileToSource);
 
18264
  SetObjectExtra (i, bfp, NULL);  
17635
18265
  SeparatorItem (s);
17636
18266
  x = SubMenu (s, "Add Type Strain Comments");
17637
18267
  i = CommandItem (x, "To All", AddTypeStrainCommentsToAll);
17640
18270
  SetObjectExtra (i, bfp, NULL);
17641
18271
  SeparatorItem (s);
17642
18272
  x = SubMenu (s, "Influenza Virus Names");
17643
 
  i = CommandItem (x, "Parse Strain and Serotype from Influenza A Virus Organisms",
 
18273
  i = CommandItem (x, "Parse Strain,Serotype from Names",
17644
18274
                   ParseInfluenzaAVirusNames);
17645
18275
  SetObjectExtra (i, bfp, NULL);
17646
 
  i = CommandItem (x, "Add Strain and Serotype to Influenza A Virus Organism Names",
 
18276
  i = CommandItem (x, "Add Strain,Serotype to Names",
17647
18277
                   AddStrainAndSerotypeToInfluenzaAVirusNames);
17648
18278
  SetObjectExtra (i, bfp, NULL);
 
18279
  i = CommandItem (x, "Fixup Organism Names", FixupInfluenzaAVirusNames);
 
18280
  SetObjectExtra (i, bfp, NULL);
17649
18281
 
17650
18282
  s = SubMenu (m, "Apply/ A");
17651
18283
  i = CommandItem (s, "Add CDS", ApplyCDS);
17669
18301
  SeparatorItem (s);
17670
18302
  i = CommandItem (s, "Add Gene Pseudo", AddGenePseudo);
17671
18303
  SetObjectExtra (i, bfp, NULL);
17672
 
  i = CommandItem (s, "Add Gene Pseudo with String Constraint", AddGenePseudoConstraint);
17673
 
  SetObjectExtra (i, bfp, NULL);
17674
18304
  i = CommandItem (s, "Add Gene Pseudo where Feature is Pseudo", MarkGenesWithPseudoFeaturesPseudo);
17675
18305
  SetObjectExtra (i, bfp, NULL);
17676
 
  x = SubMenu (s, "Apply GDS Keyword");
17677
 
  i = CommandItem (x, "Without Constraint", ApplyGDSKeyword);
17678
 
  SetObjectExtra (i, bfp, NULL);
17679
 
  i = CommandItem (x, "With Constraint", ApplyGDSKeywordWithStringConstraint);
17680
 
  SetObjectExtra (i, bfp, NULL);
 
18306
  if (indexerVersion)
 
18307
  {
 
18308
    x = SubMenu (s, "Apply Keyword");
 
18309
    i = CommandItem (x, "GDS", ApplyGDSKeyword);
 
18310
    SetObjectExtra (i, bfp, NULL);
 
18311
    i = CommandItem (x, "TPA:inferential", ApplyTPAInferentialKeyword);
 
18312
    SetObjectExtra (i, bfp, NULL);
 
18313
    i = CommandItem (x, "TPA:experimental", ApplyTPAExperimentalKeyword);
 
18314
    SetObjectExtra (i, bfp, NULL);
 
18315
    i = CommandItem (x, "With Constraint", ApplyKeywordWithStringConstraint);
 
18316
    SetObjectExtra (i, bfp, NULL);
 
18317
  }
 
18318
  else
 
18319
  {
 
18320
    i = CommandItem (s, "GDS", ApplyGDSKeyword);
 
18321
    SetObjectExtra (i, bfp, NULL);
 
18322
  }
 
18323
  
17681
18324
  
17682
18325
  i = CommandItem (s, "Apply Coding Region Frame", ApplyCDSFrame);
17683
18326
  SetObjectExtra (i, bfp, NULL);
17693
18336
 
17694
18337
  i = CommandItem (s, "Remove Qualifiers", RemoveGBQual);
17695
18338
  SetObjectExtra (i, bfp, NULL);
 
18339
  
 
18340
  if (indexerVersion)
 
18341
  {
 
18342
    i = CommandItem (s, "Remove Keywords", RemoveKeywordWithStringConstraint);
 
18343
    SetObjectExtra (i, bfp, NULL);
 
18344
  }
17696
18345
 
17697
18346
  SeparatorItem (s);
17698
18347
  i = CommandItem (s, "Remove Alignments", RemoveAlignment);
17699
18348
  SetObjectExtra (i, bfp, NULL);
17700
18349
  i = CommandItem (s, "Remove Graphs", RemoveGraph);
17701
18350
  SetObjectExtra (i, bfp, NULL);
17702
 
  i = CommandItem (s, "Remove Proteins", RemoveProteins);
 
18351
  x = SubMenu (s, "Remove Proteins");
 
18352
  i = CommandItem (x, "Just Remove Proteins", RemoveProteins);
17703
18353
  SetObjectExtra (i, bfp, NULL);
17704
 
  i = CommandItem (s, "Remove Proteins and Renormalize Nuc-Prot Sets", RemoveProteinsAndRenormalize);
 
18354
  i = CommandItem (x, "Remove Proteins and Renormalize Nuc-Prot Sets", RemoveProteinsAndRenormalize);
17705
18355
  SetObjectExtra (i, bfp, NULL);
17706
18356
  SeparatorItem (s);
17707
18357
  i = CommandItem (s, "Remove Source Qualifier", RemoveSourceQual);
17753
18403
  SetObjectExtra (i, bfp, NULL);
17754
18404
  i = CommandItem (x, "Feats", RemoveDuplicateFeats);
17755
18405
  SetObjectExtra (i, bfp, NULL);
17756
 
  i = CommandItem (s, "Remove Gene Xrefs", NewRemoveGeneXrefs);
17757
 
  SetObjectExtra (i, bfp, NULL);
17758
 
  i = CommandItem (s, "Remove Unnecessary Gene Xrefs", RemoveGeneXrefs);
17759
 
  SetObjectExtra (i, bfp, NULL);
17760
 
  i = CommandItem (s, "Remove Non-Suppressing Gene Xrefs", RemoveNSGeneXrefs);
17761
 
  SetObjectExtra (i, bfp, NULL);
17762
 
  i = CommandItem (s, "Remove Gene Xrefs with Orphan Gene Locus", RemoveGeneXrefsNoGene);
17763
 
  SetObjectExtra (i, bfp, NULL);
17764
 
  i = CommandItem (s, "Remove Gene Xrefs with Orphan Locus_tag", RemoveGeneXrefsNoLocTag);
17765
 
  SetObjectExtra (i, bfp, NULL);
17766
 
  i = CommandItem (s, "Remove ALL Gene Xrefs", RemoveAllGeneXrefs);
 
18406
  x = SubMenu (s, "Remove Gene Xrefs");
 
18407
  i = CommandItem (x, "Choose Types and Constraint", NewRemoveGeneXrefs);
 
18408
  SetObjectExtra (i, bfp, NULL);
 
18409
  i = CommandItem (x, "Unnecessary Gene Xrefs", RemoveGeneXrefs);
 
18410
  SetObjectExtra (i, bfp, NULL);
 
18411
  i = CommandItem (x, "Non-Suppressing Gene Xrefs", RemoveNSGeneXrefs);
 
18412
  SetObjectExtra (i, bfp, NULL);
 
18413
  i = CommandItem (x, "Gene Xrefs with Orphan Gene Locus", RemoveGeneXrefsNoGene);
 
18414
  SetObjectExtra (i, bfp, NULL);
 
18415
  i = CommandItem (x, "Gene Xrefs with Orphan Locus_tag", RemoveGeneXrefsNoLocTag);
 
18416
  SetObjectExtra (i, bfp, NULL);
 
18417
  i = CommandItem (x, "ALL Gene Xrefs", RemoveAllGeneXrefs);
17767
18418
  SetObjectExtra (i, bfp, NULL);
17768
18419
  SeparatorItem (s);
17769
18420
  i = CommandItem (s, "Remove Selected Features", RemoveSelFeats);
17878
18529
  i = CommandItem (s, "Convert RNA Qual", ConvertRNAQual);
17879
18530
  SetObjectExtra (i, bfp, NULL);
17880
18531
 
17881
 
  i = CommandItem (s, "CDS with internal Stop Codon to Misc Feat",
 
18532
  i = CommandItem (s, "CDS with Internal Stop Codon to Misc Feat",
17882
18533
                   ConvertCDSWithStopCodons);
17883
18534
  SetObjectExtra (i, bfp, NULL);
17884
18535
 
17885
 
  x = SubMenu (s, "CDS with internal Stop Codon to Pseudo Gene");
 
18536
  x = SubMenu (s, "CDS with Internal Stop Codon to Pseudo Gene");
17886
18537
  i = CommandItem (x, "Keep CDS", ConvertCDSToPseudoGeneAndKeep);
17887
18538
  SetObjectExtra (i, bfp, NULL);
17888
18539
  i = CommandItem (x, "Remove CDS", ConvertCDSToPseudoGeneAndRemove);
17889
18540
  SetObjectExtra (i, bfp, NULL);
17890
18541
  
17891
 
  i = CommandItem (s, "Convert Protein Names for Pseudo-CDSs to Protein Descriptions", ConvertPseudoProteinNamesToProteinDescriptions);
 
18542
  i = CommandItem (s, "Convert Bad Inference Qualifiers to Notes", ConvertBadInferenceToNote);
17892
18543
  SetObjectExtra (i, bfp, NULL);
17893
18544
  SeparatorItem (s);
17894
18545
 
17925
18576
  SetObjectExtra (i, bfp, NULL);
17926
18577
  SeparatorItem (s);
17927
18578
 
17928
 
  i = CommandItem (s, "Pub Descriptor to Feature", ConvertPubDescToFeat);
 
18579
  x = SubMenu (s, "Pub Descriptor To Feature");
 
18580
  i = CommandItem (x, "All", ConvertPubDescToFeat);
17929
18581
  SetObjectExtra (i, bfp, NULL);
17930
 
  i = CommandItem (s, "Pub Descriptor to Feature by Constraint", CreateConvertPubDescStringConstraintDialog);
 
18582
  i = CommandItem (x, "By Constraint", CreateConvertPubDescStringConstraintDialog);
17931
18583
  SetObjectExtra (i, bfp, NULL);
17932
18584
  i = CommandItem (s, "Source Descriptor to Feature", ConvertSrcDescToFeat);
17933
18585
  SetObjectExtra (i, bfp, NULL);
17969
18621
  i = CommandItem (s, "Convert SegSets to Delta Sequences", ConvertSegSetToDeltaItem);
17970
18622
  SetObjectExtra (i, bfp, NULL);
17971
18623
#endif
17972
 
  SeparatorItem (s);
17973
 
  i = CommandItem (s, "Convert Selected Gaps to Known Length", ConvertSelectedGapFeaturesToKnown);
17974
 
  SetObjectExtra (i, bfp, NULL);
17975
 
  i = CommandItem (s, "Convert Selected Gaps to Unnown Length", ConvertSelectedGapFeaturesToUnknown);
17976
 
  SetObjectExtra (i, bfp, NULL);
17977
 
  i = CommandItem (s, "Convert Adjacent Known Length Gap Pairs to Single Known Length Gaps", ConvertAdjacentKnownGapsToSingleGaps);
17978
 
  SetObjectExtra (i, bfp, NULL);
17979
18624
 
17980
18625
  s = SubMenu (m, "Edit/ E");
17981
18626
  i = CommandItem (s, "Edit Qualifiers", EditGBQual);
18007
18652
  SetObjectExtra (i, bfp, NULL);
18008
18653
  i = CommandItem (x, "Inference", FeatureInferenceEditor);
18009
18654
  SetObjectExtra (i, bfp, NULL);
 
18655
  i = CommandItem (x, "Pseudo", FeaturePseudoEditor);
 
18656
  SetObjectExtra (i, bfp, NULL);
18010
18657
 
18011
18658
  SeparatorItem (s);
18012
18659
  i = CommandItem (s, "Extend Gene", ExtendGeneReg);
18107
18754
  i = CommandItem (x, "With Comment", AddTranslExceptWithComment);
18108
18755
  SetObjectExtra (i, bfp, NULL);
18109
18756
  SeparatorItem (s);
18110
 
  i = CommandItem (s, "Fix Publication Title Capitalization", FixTitleCapitalization);
 
18757
  x = SubMenu (s, "Fix Publication Capitalization");
 
18758
  i = CommandItem (x, "In Titles", FixTitleCapitalization);
18111
18759
  SetObjectExtra (i, bfp, NULL);
18112
 
  i = CommandItem (s, "Fix Publication Affiliation Capitalization", FixAffiliationCapitalization);
 
18760
  i = CommandItem (x, "In Affiliations", FixAffiliationCapitalization);
18113
18761
  SetObjectExtra (i, bfp, NULL);
18114
18762
  SeparatorItem (s);
18115
18763
  x = SubMenu (s, "Fix Authors");
18138
18786
  SetObjectExtra (i, bfp, NULL);
18139
18787
  
18140
18788
  SeparatorItem (s);
18141
 
  i = CommandItem (s, "Parse CollectionDate formats, Month First",
18142
 
                   ParseCollectionDateMonthFirst);
18143
 
  SetObjectExtra (i, bfp, NULL);
18144
 
  i = CommandItem (s, "Parse CollectionDate formats, Day First",
18145
 
                   ParseCollectionDateDayFirst);
18146
 
  SetObjectExtra (i, bfp, NULL);
18147
 
 
 
18789
  i = CommandItem (s, "Renormalize Nuc-Prot Sets", RenormalizeNucProtSetsMenuItem);
 
18790
  SetObjectExtra (i, bfp, NULL);
 
18791
  
18148
18792
  s = SubMenu (m, "Select/ S");
18149
18793
  i = CommandItem (s, "Select Descriptors", SelectDescriptor);
18150
18794
  SetObjectExtra (i, bfp, NULL);
18176
18820
  SetObjectExtra (i, bfp, NULL);
18177
18821
  i = CommandItem (x, "Ignore Stop Codon Except at End of Complete CDS", RetranslateCdRegionsNoStopExceptEndCompleteCDS);
18178
18822
  SetObjectExtra (i, bfp, NULL);
18179
 
  i = CommandItem (s, "Adjust CDS Locations for Gaps", AdjustCDSLocationsForGaps);
18180
 
  SetObjectExtra (i, bfp, NULL);
18181
18823
  i = CommandItem (s, "Retranscribe mRNA Products", ReprocessmRNAProducts);
18182
18824
  SetObjectExtra (i, bfp, NULL);
18183
18825
  i = CommandItem (s, "Regenerate Peptide Products", ReprocessPeptideProducts);
18214
18856
  SeparatorItem (s);
18215
18857
  i = CommandItem (s, "Package Features on Parts", PackageOnParts);
18216
18858
  SetObjectExtra (i, bfp, NULL);
 
18859
  i = CommandItem (s, "Force Features into one SeqAnnot", ForceRepackage);
 
18860
  SetObjectExtra (i, bfp, NULL);
18217
18861
  SeparatorItem (s);
18218
18862
  i = CommandItem (s, "Package Proteins on Nucleotides", PackageOnNucs);
18219
18863
  SetObjectExtra (i, bfp, NULL);
18220
18864
  SeparatorItem (s);
18221
 
  i = CommandItem (s, "Delta or Segmented Sequence to Raw Sequence", SegSeqToRawSeq);
18222
 
  SetObjectExtra (i, bfp, NULL);
18223
 
  i = CommandItem (s, "Raw Sequence with Ns to Delta Sequence", 
 
18865
  
 
18866
  i = CommandItem (s, "Map Features to Protein Sequences", MapFeaturesToProteinSequence);
 
18867
  SetObjectExtra (i, bfp, NULL);
 
18868
  SeparatorItem (s);
 
18869
  
 
18870
  x = SubMenu (s, "Gap Functions");
 
18871
  y = SubMenu (x, "Create");
 
18872
  i = CommandItem (y, "Delta or Segmented Sequence to Raw Sequence", SegSeqToRawSeq);
 
18873
  SetObjectExtra (i, bfp, NULL);
 
18874
  i = CommandItem (y, "Raw Sequence with Ns to Delta Sequence", 
18224
18875
                   RawSeqToDeltaSeqUnknownWithUnknownLengthGaps);
18225
18876
  SetObjectExtra (i, bfp, NULL);
18226
 
  i = CommandItem (s, "Convert Raw Sequences To Delta Sequences with Known Gap Locations",
 
18877
  i = CommandItem (y, "Raw Sequences To Delta Sequences with Known Gap Locations",
18227
18878
                   ConvertRawToDeltaWithGapLocations);
18228
18879
  SetObjectExtra (i, bfp, NULL);
 
18880
  y = SubMenu (x, "Convert");
 
18881
  i = CommandItem (y, "Convert Selected Gaps to Known Length", ConvertSelectedGapFeaturesToKnown);
 
18882
  SetObjectExtra (i, bfp, NULL);
 
18883
  i = CommandItem (y, "Convert Selected Gaps to Unknown Length", ConvertSelectedGapFeaturesToUnknown);
 
18884
  SetObjectExtra (i, bfp, NULL);
 
18885
  i = CommandItem (y, "Convert Known-length Gaps to Unknown Length by Size", ConvertGapFeaturesToUnknown);
 
18886
  SetObjectExtra (i, bfp, NULL);
 
18887
  i = CommandItem (y, "Change Length of Selected Known-length Gaps", ChangeKnownGapLength);
 
18888
  SetObjectExtra (i, bfp, NULL);
 
18889
  i = CommandItem (y, "Expand Known-length Gaps to Include Flanking Ns", AddFlankingNsToKnownLengthGaps);
 
18890
  SetObjectExtra (i, bfp, NULL);
 
18891
  i = CommandItem (y, "Combine Adjacent Gaps", CombineAdjacentGaps);
 
18892
  SetObjectExtra (i, bfp, NULL);
 
18893
  SeparatorItem (y);
 
18894
  z = SubMenu (y, "Adjust CDS Locations for Gaps");
 
18895
  i = CommandItem (z, "Unknown Length Gaps Only", AdjustCDSLocationsForGaps);
 
18896
  SetObjectExtra (i, bfp, NULL);
 
18897
  i = CommandItem (z, "Known and Unknown Length Gaps", AdjustCDSLocationsForGapsKnownAndUnknown);
 
18898
  SetObjectExtra (i, bfp, NULL);
 
18899
  i = CommandItem (y, "Trim Coding Regions and mRNAs for Known Gaps", AdjustCodingRegionsEndingInGap);
 
18900
  SetObjectExtra (i, bfp, NULL);
 
18901
  i = CommandItem (y, "Convert Coding Regions with Internal Gaps to Misc_feat", ConvertCodingRegionsWithInternalKnownGapToMiscFeat);
 
18902
  SetObjectExtra (i, bfp, NULL);
 
18903
  SeparatorItem (y);
 
18904
  i = CommandItem (y, "Fix Delta SeqDataLen", FixDeltaSeqDataLen);
 
18905
  SetObjectExtra (i, bfp, NULL);
 
18906
  
 
18907
  SeparatorItem (s);
 
18908
  x = SubMenu (s, "Gap Features");
 
18909
  i = CommandItem (x, "Instantiate from Delta Instructions", InstantiateGapFeatures);
 
18910
  SetObjectExtra (i, bfp, NULL);
 
18911
  SeparatorItem (x);
 
18912
  i = CommandItem (x, "Remove Unnecessary Gap Features", RemoveUnnecessaryGapFeatures);
 
18913
  SetObjectExtra (i, bfp, NULL);
 
18914
 
18229
18915
  SeparatorItem (s);
18230
18916
  x = SubMenu (s, "Generate GenProdSet Redundancy");
18231
18917
  i = CommandItem (x, "With Descriptor Propagation", MakeRedundantGPSwithProp);
18235
18921
  i = CommandItem (x, "Just Copy CDS Prot Xref", MakeRedundantGPSjustXref);
18236
18922
  SetObjectExtra (i, bfp, NULL);
18237
18923
  SeparatorItem (s);
 
18924
  i = CommandItem (s, "Copy Far Prot Xref to CDS", MakeRedundantGenomicProtXref);
 
18925
  SetObjectExtra (i, bfp, NULL);
 
18926
  SeparatorItem (s);
18238
18927
  i = CommandItem (s, "Convert Pseudo CDS to Misc_feat", ConvertPseudoCDSToMiscFeat);
18239
18928
  SetObjectExtra (i, bfp, NULL);
18240
18929
  i = CommandItem (s, "Process Pseudo Misc_feats", ProcessPseudoMiscFeat);
18314
19003
  SeparatorItem (s);
18315
19004
  i  = CommandItem (s, "Gene Features From Other Features", FeatureToGene);
18316
19005
  SetObjectExtra (i, bfp, NULL);
18317
 
  i = CommandItem (s, "CDS Features from Gene", GeneToCds);
18318
 
  SetObjectExtra (i, bfp, NULL);
18319
19006
  i = CommandItem (s, "CDS Features from Gene, mRNA, or exon", FeatureToCds);
18320
19007
  SetObjectExtra (i, bfp, NULL);
18321
19008
  SeparatorItem (s);
18346
19033
    i = CommandItem (s, "Reload Publications", LookupAllPubs);
18347
19034
    SetObjectExtra (i, bfp, NULL);
18348
19035
    SeparatorItem (s);
18349
 
    i = CommandItem (s, "Fix Delta SeqDataLen", FixDeltaSeqDataLen);
18350
 
    SetObjectExtra (i, bfp, NULL);
18351
 
    SeparatorItem (s);
18352
19036
    x = SubMenu (s, "Add BLAST tag to Seq-annot");
18353
19037
    i = CommandItem (x, "BLASTN", AddBlastNToSeqAnnot);
18354
19038
    SetObjectExtra (i, bfp, NULL);
18366
19050
  }
18367
19051
 
18368
19052
  s = SubMenu (m, "Link/ K");
18369
 
  i = CommandItem (s, "Assign Feature IDs to CDS and mRNA", AssignFeatIDs);
 
19053
  i = CommandItem (s, "Assign Feature IDs", AssignFeatIDs);
18370
19054
  SetObjectExtra (i, bfp, NULL);
18371
19055
  i = CommandItem (s, "Clear Feature IDs and Links", ClearFeatIDsAndLinks);
18372
19056
  SetObjectExtra (i, bfp, NULL);
18381
19065
  SeparatorItem (s);
18382
19066
  i = CommandItem (s, "Show Linked CDS or mRNA Feature", SelCDSmRNALink);
18383
19067
  SetObjectExtra (i, bfp, NULL);
 
19068
  SeparatorItem (s);
 
19069
  i = CommandItem (s, "Reassign Feature IDs", ReassignFeatIDs);
 
19070
  SetObjectExtra (i, bfp, NULL);
18384
19071
 
18385
19072
  SeparatorItem (m);
18386
19073
  i = CommandItem (m, "Sort Unique Count/ U", SUCProc);
18426
19113
    SetObjectExtra (i, bfp, NULL);
18427
19114
    i = CommandItem (s, "Indexer", TestExtendSequenceSetIndexer);
18428
19115
    SetObjectExtra (i, bfp, NULL);
18429
 
    
 
19116
    SeparatorItem (m);
 
19117
    i = CommandItem (m, "Discrepancy Report", ShowDiscrepancyReport);
 
19118
    SetObjectExtra (i, bfp, NULL);
18430
19119
    
18431
19120
  }
18432
19121
/*#ifdef INTERNAL_NCBI_SEQUIN*/