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

« back to all changes in this revision

Viewing changes to sequin/sequin6.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:   11/12/97
31
31
*
32
 
* $Revision: 6.234 $
 
32
* $Revision: 6.250 $
33
33
*
34
34
* File Description: 
35
35
*
248
248
  {"Forma",                    25},
249
249
  {"Forma-specialis",          26},
250
250
  {"Frequency",              1013},
251
 
  {"Fwd-primer-name",        1035},
252
 
  {"Fwd-primer-seq",         1033},
 
251
  {"Fwd-PCR-primer-name",    1035},
 
252
  {"Fwd-PCR-primer-seq",     1033},
253
253
  {"Genotype",               1006},
254
254
  {"Germline",               1014},
255
255
  {"Group",                    15},
270
270
  {"Plastid-name",           1022},
271
271
  {"Pop-variant",            1017},
272
272
  {"Rearranged",             1015},
273
 
  {"Rev-primer-name",        1036},
274
 
  {"Rev-primer-seq",         1034},
 
273
  {"Rev-PCR-primer-name",    1036},
 
274
  {"Rev-PCR-primer-seq",     1034},
275
275
  {"Segment",                1024},
276
276
  {"Serogroup",                 8},
277
277
  {"Serotype",                  7},
355
355
  {"Endogenous-virus-name", 25},
356
356
  {"Environmental-sample",  27},
357
357
  {"Frequency",             13},
358
 
  {"Fwd-primer-name",       35},
359
 
  {"Fwd-primer-seq",        33},
 
358
  {"Fwd-PCR-primer-name",   35},
 
359
  {"Fwd-PCR-primer-seq",    33},
360
360
  {"Genotype",               6},
361
361
  {"Germline",              14},
362
362
  {"Haplotype",              5},
373
373
  {"Plastid-name",          22},
374
374
  {"Pop-variant",           17},
375
375
  {"Rearranged",            15},
376
 
  {"Rev-primer-name",       36},
377
 
  {"Rev-primer-seq",        34},
 
376
  {"Rev-PCR-primer-name",   36},
 
377
  {"Rev-PCR-primer-seq",    34},
378
378
  {"Segment",               24},
379
379
  {"Sex",                    7},
380
380
  {"Subclone",               4},
5902
5902
  TexT           left_end;
5903
5903
  TexT           right_end;
5904
5904
  ButtoN         add_to_seq_with_like_feature;
 
5905
  ButtoN         also_add_mRNA_btn;
5905
5906
  ButtoN         leaveDlgUp;
5906
5907
  
5907
5908
  GetSamplePtr   gsp;
6336
6337
  return gap_in_location;
6337
6338
}
6338
6339
 
6339
 
static SeqLocPtr RemoveGapsFromDeltaLocation (SeqLocPtr slp, BioseqPtr bsp)
 
6340
static SeqLocPtr RemoveGapsFromDeltaLocation (SeqLocPtr slp, BioseqPtr bsp, Boolean also_known_gaps)
6340
6341
{
6341
6342
  DeltaSeqPtr dsp;
6342
6343
  Int4        seq_offset = 0;
6346
6347
  SeqIdPtr    sip, before_sip, after_sip;
6347
6348
  Boolean     changed, partial5, partial3;
6348
6349
  SeqLocPtr   before = NULL, after = NULL;
 
6350
  Boolean     is_first = TRUE;
6349
6351
 
6350
6352
  if (slp == NULL || bsp == NULL 
6351
6353
      || bsp->repr != Seq_repr_delta
6385
6387
    {
6386
6388
      slip = (SeqLitPtr) (dsp->data.ptrvalue);  
6387
6389
      if (slip->seq_data == NULL
6388
 
          && slip->fuzz != NULL 
 
6390
          && (also_known_gaps || slip->fuzz != NULL)
6389
6391
          && GapInLocation (seq_offset, slip->length, before))
6390
6392
      {
6391
6393
        /* we make a copy of the original location */
6403
6405
        after = SeqLocDeleteEx (after, after_sip,
6404
6406
                          0, seq_offset + slip->length - 1,
6405
6407
                          FALSE, &changed, &partial5, &partial3);
 
6408
                          
 
6409
        /* make not partial on the side where the gap was */
 
6410
        SetSeqLocPartial (after, FALSE, partial3);
 
6411
        
6406
6412
        /* in the "before" location, we free everything after the
6407
6413
         * beginning of the gap.
6408
6414
         */
6410
6416
                          seq_offset, bsp->length,
6411
6417
                          FALSE, &changed, &partial5, &partial3);
6412
6418
        
 
6419
        /* make not partial on the side where the gap was */
 
6420
        if (!is_first) {
 
6421
            partial5 = FALSE;
 
6422
        }
 
6423
        SetSeqLocPartial (before, partial5, FALSE);
 
6424
        
6413
6425
        /* we're done with these IDs now */                  
6414
6426
        after_sip = SeqIdFree (after_sip);
6415
6427
        before_sip = SeqIdFree (before_sip);                          
6431
6443
          prev_loc = before;
6432
6444
        }        
6433
6445
        before = after;
 
6446
        /* all additional intervals will be 5' complete */
 
6447
        is_first = FALSE;
6434
6448
      }
6435
6449
      seq_offset += slip->length;
 
6450
      
6436
6451
    }
6437
6452
  }
6438
6453
 
6440
6455
  return loc_list;  
6441
6456
}
6442
6457
 
6443
 
static SeqLocPtr RemoveGapsFromLocation (SeqLocPtr slp)
 
6458
static SeqLocPtr RemoveGapsFromLocation (SeqLocPtr slp, Boolean also_known_gaps)
6444
6459
{
6445
6460
  BioseqPtr   bsp;
6446
6461
  SeqIdPtr    sip;
6469
6484
          && bsp->seq_ext_type == 4
6470
6485
          && bsp->seq_ext != NULL)
6471
6486
  {
6472
 
    return RemoveGapsFromDeltaLocation (slp, bsp);
 
6487
    return RemoveGapsFromDeltaLocation (slp, bsp, also_known_gaps);
6473
6488
  }
6474
6489
  else
6475
6490
  {
6635
6650
  CdRegionPtr crp;
6636
6651
  Boolean     partial5, partial3;
6637
6652
  Uint2       entityID;
 
6653
  Boolean     also_known_gaps = FALSE;
 
6654
  SeqLocPtr   slp_mix;
6638
6655
  
6639
6656
  if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION)
6640
6657
  {
6641
6658
    return;
6642
6659
  }
 
6660
  
 
6661
  if (userdata != NULL) {
 
6662
      also_known_gaps = *((BoolPtr)userdata);
 
6663
  }
6643
6664
 
6644
6665
  gapped_bioseq = (BioseqPtr) userdata;
6645
6666
  sfp_bsp = BioseqFind (SeqLocId (sfp->location));
6654
6675
  }
6655
6676
  
6656
6677
  CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
6657
 
  sfp->location = RemoveGapsFromLocation (sfp->location);
 
6678
  sfp->location = RemoveGapsFromLocation (sfp->location, also_known_gaps);
6658
6679
 
6659
6680
  if (gapped_bioseq != NULL && gapped_bioseq->repr == Seq_repr_delta)
6660
6681
  {
6726
6747
    }
6727
6748
    SetProductSequencePartials (protbsp, partial5, partial3);
6728
6749
  }
 
6750
  else 
 
6751
  {
 
6752
    /* make location mixed */
 
6753
    slp_mix = ValNodeNew(NULL);
 
6754
    slp_mix->choice = SEQLOC_MIX;
 
6755
    slp_mix->data.ptrvalue = sfp->location;
 
6756
    sfp->location = slp_mix;
 
6757
  }
6729
6758
}
6730
6759
 
6731
 
extern void AdjustCDSLocationsForGaps (IteM i)
 
6760
static void AdjustCDSLocationsForGapsEx (IteM i, Boolean also_known_gaps)
6732
6761
{
6733
6762
  BaseFormPtr bfp;
6734
6763
  SeqEntryPtr sep, oldscope;
6742
6771
 
6743
6772
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
6744
6773
  oldscope = SeqEntrySetScope (sep);
6745
 
  VisitFeaturesInSep (sep, NULL, AdjustCDSLocationsForGapsCallback);
 
6774
  VisitFeaturesInSep (sep, &also_known_gaps, AdjustCDSLocationsForGapsCallback);
6746
6775
 
6747
6776
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
6748
6777
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
6749
6778
  SeqEntrySetScope (oldscope);
6750
6779
}
6751
6780
 
 
6781
 
 
6782
extern void AdjustCDSLocationsForGaps (IteM i)
 
6783
{
 
6784
  AdjustCDSLocationsForGapsEx(i, FALSE);
 
6785
}
 
6786
 
 
6787
 
 
6788
extern void AdjustCDSLocationsForGapsKnownAndUnknown (IteM i)
 
6789
{
 
6790
  AdjustCDSLocationsForGapsEx(i, TRUE);
 
6791
}
 
6792
 
 
6793
 
6752
6794
static ValNodePtr GapLocationsFromNs (BioseqPtr bsp, Int4Ptr gap_sizes)
6753
6795
 
6754
6796
{
6879
6921
 
6880
6922
static SeqLocPtr 
6881
6923
RemoveGapLocationsFromSeqLoc 
6882
 
(SeqLocPtr slp, 
 
6924
(SeqLocPtr  slp, 
6883
6925
 ValNodePtr gap_locs, 
6884
 
 BioseqPtr bsp)
 
6926
 BioseqPtr  bsp,
 
6927
 BoolPtr    loc_changed)
6885
6928
{
6886
6929
  ValNodePtr    gap_vnp;
6887
6930
  GapLocInfoPtr glip;
6890
6933
  Boolean     changed, partial5, partial3;
6891
6934
  SeqLocPtr   before = NULL, after = NULL;
6892
6935
 
 
6936
  if (loc_changed != NULL)
 
6937
  {
 
6938
    *loc_changed = FALSE;
 
6939
  }
 
6940
  
6893
6941
  if (slp == NULL || gap_locs == NULL || bsp == NULL)
6894
6942
  {
6895
6943
    return slp;
6917
6965
    }
6918
6966
    if (GapInLocation (glip->start_pos, glip->length, before))
6919
6967
    {
 
6968
      if (loc_changed != NULL)
 
6969
      {
 
6970
        *loc_changed = TRUE;
 
6971
      }
6920
6972
      /* we make a copy of the original location */
6921
6973
      after = SeqLocCopy (before);
6922
6974
      
6968
7020
  return loc_list;  
6969
7021
}
6970
7022
 
 
7023
const char *cds_gap_comment = "coding region disrupted by sequencing gap";
 
7024
 
 
7025
static void AddCDSGapComment (SeqFeatPtr sfp)
 
7026
{
 
7027
  CharPtr new_comment = NULL;
 
7028
  
 
7029
  if (sfp == NULL)
 
7030
  {
 
7031
    return;
 
7032
  }
 
7033
  
 
7034
  if (StringHasNoText (sfp->comment))
 
7035
  {
 
7036
    sfp->comment = MemFree (sfp->comment);
 
7037
    sfp->comment = StringSave (cds_gap_comment);
 
7038
  }
 
7039
  else
 
7040
  {
 
7041
    new_comment = (CharPtr) MemNew ((StringLen (sfp->comment) 
 
7042
                                     + StringLen (cds_gap_comment)
 
7043
                                     + 4) * sizeof (Char));
 
7044
    StringCpy (new_comment, sfp->comment);
 
7045
    StringCat (new_comment, "; ");
 
7046
    StringCat (new_comment, cds_gap_comment);
 
7047
    sfp->comment = MemFree (sfp->comment);
 
7048
    sfp->comment = new_comment;
 
7049
  }
 
7050
}
 
7051
 
6971
7052
static void AdjustCodingRegionLocationsForGapLocations (BioseqPtr bsp, ValNodePtr gap_list)
6972
7053
{
6973
7054
  SeqFeatPtr        sfp;
6977
7058
  CdRegionPtr       crp;
6978
7059
  Boolean           partial5, partial3;
6979
7060
  Uint2             entityID;
 
7061
  Boolean           loc_changed;
6980
7062
  
6981
7063
  if (bsp == NULL || gap_list == NULL)
6982
7064
  {
6990
7072
       sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_CDREGION, 0, &fcontext))
6991
7073
  {
6992
7074
    CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
6993
 
    sfp->location = RemoveGapLocationsFromSeqLoc (sfp->location, gap_list, bsp);
 
7075
    loc_changed = FALSE;
 
7076
    sfp->location = RemoveGapLocationsFromSeqLoc (sfp->location, gap_list, bsp, &loc_changed);
 
7077
    if (!loc_changed) {
 
7078
        return;
 
7079
    }
 
7080
    if (loc_changed)
 
7081
    {
 
7082
      AddCDSGapComment (sfp);
 
7083
    }
6994
7084
   
6995
7085
    while (sfp->location->next != NULL)
6996
7086
    {
7003
7093
                                                       (AsnWriteFunc) CdRegionAsnWrite);
7004
7094
        new_sfp->data.value.ptrvalue = crp;
7005
7095
        new_sfp->location = sfp->location->next;
 
7096
        new_sfp->comment = StringSave (sfp->comment);
7006
7097
 
7007
7098
        protbsp = BioseqFindFromSeqLoc (sfp->product);        
7008
7099
        if (protbsp != NULL)
7081
7172
  gap_locations = ValNodeFreeData (gap_locations);
7082
7173
}
7083
7174
 
 
7175
static Int4 
 
7176
CalculateGapCoverage 
 
7177
(BioseqPtr         bsp, 
 
7178
 SeqLocPtr         slp, 
 
7179
 SeqMgrFeatContext context,
 
7180
 Boolean           include_terminal_gaps)
 
7181
{
 
7182
  DeltaSeqPtr       dsp;
 
7183
  SeqLocPtr         loc;
 
7184
  SeqLitPtr         slip;
 
7185
  Int4              seq_offset = 0;
 
7186
  Int4              covered = 0;
 
7187
  Int4              k, start, stop;
 
7188
 
 
7189
  if (slp == NULL
 
7190
      || bsp == NULL || !ISA_na (bsp->mol) 
 
7191
      || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4)
 
7192
  {
 
7193
    return 0;
 
7194
  }
 
7195
  
 
7196
  dsp = (DeltaSeqPtr) bsp->seq_ext;
 
7197
  while (dsp != NULL && seq_offset < context.right)
 
7198
  {
 
7199
    if (dsp->choice == 1)
 
7200
    {
 
7201
      loc = (SeqLocPtr) dsp->data.ptrvalue;
 
7202
      if (loc != NULL)
 
7203
      {
 
7204
        seq_offset += SeqLocLen (loc);
 
7205
      }
 
7206
    }
 
7207
    else if (dsp->choice == 2)
 
7208
    {
 
7209
      slip = (SeqLitPtr) dsp->data.ptrvalue;
 
7210
      if (slip != NULL)
 
7211
      {
 
7212
        if (slip->seq_data == NULL
 
7213
            && slip->fuzz == NULL)
 
7214
        {        
 
7215
          if (seq_offset <= context.left && seq_offset + slip->length >= context.right)
 
7216
          {
 
7217
            /* gap covers entire location */
 
7218
            return SeqLocLen (slp);
 
7219
          }
 
7220
          else if (include_terminal_gaps || 
 
7221
                   (seq_offset > context.left 
 
7222
                    && seq_offset + slip->length < context.right))
 
7223
          {
 
7224
            /* we only count internal gaps */
 
7225
            for (k = 0; k < context.numivals; k += 2) 
 
7226
            {
 
7227
              start = context.ivals [k];
 
7228
              stop = context.ivals [k + 1];
 
7229
              if (seq_offset <= start && seq_offset + slip->length > stop)
 
7230
              {
 
7231
                /* gap covers entire interval */
 
7232
                covered += stop - start;
 
7233
              }
 
7234
              else if (seq_offset > start && seq_offset + slip->length < stop)
 
7235
              {
 
7236
                /* interval covers entire gap */
 
7237
                covered += slip->length;
 
7238
              }
 
7239
              else if (seq_offset < start && seq_offset + slip->length < stop)
 
7240
              {
 
7241
                /* gap covers left end of interval */
 
7242
                covered += seq_offset + slip->length - start;
 
7243
              }
 
7244
              else if (seq_offset > start && seq_offset + slip->length > stop)
 
7245
              {
 
7246
                /* gap covers right end of interval */
 
7247
                covered += stop - seq_offset;
 
7248
              }
 
7249
            }
 
7250
          }
 
7251
        }
 
7252
        seq_offset += slip->length;
 
7253
      }
 
7254
    }
 
7255
    dsp = dsp->next;
 
7256
  }
 
7257
 
 
7258
  return covered;
 
7259
  
 
7260
}
 
7261
 
 
7262
static SeqLocPtr 
 
7263
RemoveTerminalGapsFromLocation
 
7264
(BioseqPtr         bsp, 
 
7265
 SeqLocPtr         slp,
 
7266
 SeqMgrFeatContext context)
 
7267
{
 
7268
  DeltaSeqPtr       dsp;
 
7269
  SeqLocPtr         loc, slp_copy;
 
7270
  SeqLitPtr         slip;
 
7271
  Int4              seq_offset = 0;
 
7272
  SeqIdPtr          sip;
 
7273
  Boolean           changed = FALSE, partial5, partial3;
 
7274
 
 
7275
  if (slp == NULL)
 
7276
  {
 
7277
    return NULL;
 
7278
  }
 
7279
  
 
7280
  CheckSeqLocForPartial (slp, &partial5, &partial3);
 
7281
  
 
7282
  slp_copy = (SeqLocPtr) AsnIoMemCopy (slp, 
 
7283
                                       (AsnReadFunc) SeqLocAsnRead,
 
7284
                                       (AsnWriteFunc) SeqLocAsnWrite);
 
7285
  if (bsp == NULL || !ISA_na (bsp->mol) 
 
7286
      || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4)
 
7287
  {
 
7288
    return slp_copy;
 
7289
  }
 
7290
  
 
7291
  dsp = (DeltaSeqPtr) bsp->seq_ext;
 
7292
  while (dsp != NULL && seq_offset < context.right && slp_copy != NULL)
 
7293
  {
 
7294
    if (dsp->choice == 1)
 
7295
    {
 
7296
      loc = (SeqLocPtr) dsp->data.ptrvalue;
 
7297
      if (loc != NULL)
 
7298
      {
 
7299
        seq_offset += SeqLocLen (loc);
 
7300
      }
 
7301
    }
 
7302
    else if (dsp->choice == 2)
 
7303
    {
 
7304
      slip = (SeqLitPtr) dsp->data.ptrvalue;
 
7305
      if (slip != NULL)
 
7306
      {
 
7307
        if (slip->seq_data == NULL
 
7308
            && slip->fuzz == NULL)
 
7309
        {        
 
7310
          if (seq_offset <= context.left && seq_offset + slip->length >= context.right)
 
7311
          {
 
7312
            slp_copy = SeqLocFree (slp_copy);
 
7313
          }
 
7314
          else if (seq_offset <= context.left && seq_offset + slip->length >= context.left)
 
7315
          {
 
7316
            sip = SeqIdDup (SeqLocId (slp_copy));
 
7317
            slp_copy = SeqLocDeleteEx (slp_copy, sip,
 
7318
                              context.left, seq_offset + slip->length - 1,
 
7319
                              FALSE, &changed, &partial5, &partial3);
 
7320
            sip = SeqIdFree (sip);
 
7321
 
 
7322
          }
 
7323
          
 
7324
          if (seq_offset <= context.right && seq_offset + slip->length >= context.right)
 
7325
          {
 
7326
            sip = SeqIdDup (SeqLocId (slp_copy));
 
7327
            slp_copy = SeqLocDeleteEx (slp_copy, sip,
 
7328
                              seq_offset, context.right,
 
7329
                              FALSE, &changed, &partial5, &partial3);
 
7330
            sip = SeqIdFree (sip);
 
7331
          }
 
7332
        }
 
7333
        seq_offset += slip->length;
 
7334
      }
 
7335
    }
 
7336
    dsp = dsp->next;
 
7337
  }
 
7338
 
 
7339
  if (slp_copy != NULL)  
 
7340
  {
 
7341
    SetSeqLocPartial (slp_copy, partial5, partial3);
 
7342
  }
 
7343
 
 
7344
  return slp_copy;
 
7345
}
 
7346
 
 
7347
static void 
 
7348
AdjustOneCodingRegionWithTerminalGapsOnBioseq 
 
7349
(BioseqPtr         bsp,
 
7350
 SeqFeatPtr        sfp,
 
7351
 SeqMgrFeatContext context)
 
7352
{
 
7353
  SeqLocPtr         adjusted_loc;
 
7354
  Int4              seq_offset = 0;
 
7355
  Int4              loc_len, adjusted_len;
 
7356
  Boolean           partial5, partial3;
 
7357
  BioseqPtr         protbsp;
 
7358
  SeqFeatPtr        gene_sfp;
 
7359
  SeqMgrFeatContext gene_context;
 
7360
 
 
7361
  if (bsp == NULL || !ISA_na (bsp->mol) 
 
7362
      || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4
 
7363
      || sfp == NULL
 
7364
      || (sfp->data.choice != SEQFEAT_CDREGION && sfp->idx.subtype != FEATDEF_mRNA))
 
7365
  {
 
7366
    return;
 
7367
  }
 
7368
  
 
7369
  loc_len = SeqLocLen (sfp->location);
 
7370
  
 
7371
  adjusted_loc = RemoveTerminalGapsFromLocation (bsp, sfp->location, context);
 
7372
  adjusted_len = SeqLocLen (adjusted_loc);
 
7373
  if (adjusted_loc != NULL && adjusted_len < loc_len)
 
7374
  {
 
7375
    gene_sfp = SeqMgrGetOverlappingGene (sfp->location, &gene_context);
 
7376
    if (gene_sfp != NULL 
 
7377
        && SeqLocCompare (gene_sfp->location, sfp->location) == SLC_A_EQ_B)
 
7378
    {
 
7379
      gene_sfp->location = SeqLocFree (gene_sfp->location);
 
7380
      gene_sfp->location = (SeqLocPtr) AsnIoMemCopy (adjusted_loc,
 
7381
                                                     (AsnReadFunc) SeqLocAsnRead,
 
7382
                                                     (AsnWriteFunc) SeqLocAsnWrite);
 
7383
    }
 
7384
  
 
7385
    sfp->location = SeqLocFree (sfp->location);
 
7386
    sfp->location = adjusted_loc;
 
7387
    adjusted_loc = NULL;
 
7388
    CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
 
7389
    sfp->partial = partial5 || partial3;
 
7390
    
 
7391
    protbsp = BioseqFindFromSeqLoc (sfp->product);
 
7392
 
 
7393
    if (sfp->data.choice == SEQFEAT_CDREGION)
 
7394
    {
 
7395
      /* adjust frame */
 
7396
      AdjustFrame (sfp, protbsp);
 
7397
 
 
7398
      /* retranslate coding region */
 
7399
      SeqEdTranslateOneCDS (sfp, bsp, sfp->idx.entityID);
 
7400
              
 
7401
      /* set partials on product */
 
7402
      SetProductSequencePartials (protbsp, partial5, partial3);
 
7403
    }
 
7404
  }
 
7405
  
 
7406
  adjusted_loc = SeqLocFree (adjusted_loc);
 
7407
  
 
7408
}
 
7409
 
 
7410
static void AdjustCodingRegionsEndingInGapOnBioseq (BioseqPtr bsp, Pointer userdata)
 
7411
{
 
7412
  SeqMgrFeatContext context;
 
7413
  SeqFeatPtr        sfp;
 
7414
  
 
7415
  if (bsp == NULL || !ISA_na (bsp->mol) 
 
7416
      || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4)
 
7417
  {
 
7418
    return;
 
7419
  }
 
7420
    
 
7421
  for (sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_CDREGION, 0, &context);
 
7422
       sfp != NULL;
 
7423
       sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_CDREGION, 0, &context))
 
7424
  {
 
7425
    AdjustOneCodingRegionWithTerminalGapsOnBioseq (bsp, sfp, context);
 
7426
  }
 
7427
  for (sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_RNA, FEATDEF_mRNA, &context);
 
7428
       sfp != NULL;
 
7429
       sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_RNA, FEATDEF_mRNA, &context))
 
7430
  {
 
7431
    AdjustOneCodingRegionWithTerminalGapsOnBioseq (bsp, sfp, context);
 
7432
  }
 
7433
}
 
7434
 
 
7435
extern void AdjustCodingRegionsEndingInGap (IteM i)
 
7436
{
 
7437
  BaseFormPtr bfp;
 
7438
  SeqEntryPtr sep;
 
7439
 
 
7440
#ifdef WIN_MAC
 
7441
  bfp = currentFormDataPtr;
 
7442
#else
 
7443
  bfp = GetObjectExtra (i);
 
7444
#endif
 
7445
  if (bfp == NULL) return;
 
7446
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
7447
  if (sep == NULL) return;
 
7448
 
 
7449
  VisitBioseqsInSep (sep, NULL, AdjustCodingRegionsEndingInGapOnBioseq);
 
7450
  DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
 
7451
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
7452
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
7453
}
 
7454
 
 
7455
typedef struct cdstomiscfeatform
 
7456
{
 
7457
  FEATURE_FORM_BLOCK
 
7458
  
 
7459
  GrouP  all_or_percent_grp;
 
7460
  DialoG string_constraint_dlg;
 
7461
  
 
7462
  Boolean             convert_all;
 
7463
  FilterSetPtr        fsp;
 
7464
  StringConstraintPtr scp;
 
7465
  BioseqPtr           bsp;
 
7466
} CDSToMiscFeatFormData, PNTR CDSToMiscFeatFormPtr;
 
7467
 
 
7468
static void ConvertCDSToMiscFeatFeatureCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
 
7469
{
 
7470
  CDSToMiscFeatFormPtr cmffp;
 
7471
  Int4                 orig_len, covered_len;
 
7472
  SeqMgrFeatContext    context;
 
7473
  SeqEntryPtr          oldscope;
 
7474
 
 
7475
  cmffp = (CDSToMiscFeatFormPtr) userdata;
 
7476
  
 
7477
  if (sfp == NULL || cmffp == NULL || cmffp->bsp == NULL)
 
7478
  {
 
7479
    return;
 
7480
  }
 
7481
  
 
7482
  sfp = SeqMgrGetDesiredFeature (sfp->idx.entityID, cmffp->bsp, sfp->idx.itemID, 0, sfp, &context);
 
7483
  if (sfp == NULL)
 
7484
  {
 
7485
    return;
 
7486
  }
 
7487
  
 
7488
  oldscope = SeqEntrySetScope (NULL);
 
7489
 
 
7490
  orig_len = SeqLocLen (sfp->location);
 
7491
  covered_len = CalculateGapCoverage (cmffp->bsp, sfp->location, context, cmffp->convert_all);
 
7492
  if (covered_len >= orig_len / 2 || (cmffp->convert_all && covered_len > 0))
 
7493
  {
 
7494
    ConvertCDSToMiscFeat (sfp);
 
7495
  }
 
7496
  
 
7497
  SeqEntrySetScope (oldscope);
 
7498
}
 
7499
 
 
7500
static void ConvertGappedCodingRegionsToMiscFeatBioseqCallback (BioseqPtr bsp, Pointer userdata)
 
7501
{
 
7502
  CDSToMiscFeatFormPtr cmffp;
 
7503
  SeqEntryPtr          sep;
 
7504
  
 
7505
  if (bsp == NULL || !ISA_na (bsp->mol) 
 
7506
      || bsp->repr != Seq_repr_delta || bsp->seq_ext_type != 4
 
7507
      || userdata == NULL)
 
7508
  {
 
7509
    return;
 
7510
  }
 
7511
  
 
7512
  sep = SeqMgrGetSeqEntryForData (bsp);
 
7513
  
 
7514
  cmffp = (CDSToMiscFeatFormPtr) userdata;
 
7515
  cmffp->bsp = bsp;
 
7516
  
 
7517
  OperateOnSeqEntryConstrainedObjects (sep, cmffp->fsp, 
 
7518
                                       ConvertCDSToMiscFeatFeatureCallback,
 
7519
                                       NULL, SEQFEAT_CDREGION, FEATDEF_CDS, 0, cmffp);
 
7520
 
 
7521
}
 
7522
 
 
7523
static void AcceptCDSToMiscFeat (ButtoN b)
 
7524
{
 
7525
  CDSToMiscFeatFormPtr cmffp;
 
7526
  SeqEntryPtr          sep;
 
7527
  
 
7528
  cmffp = (CDSToMiscFeatFormPtr) GetObjectExtra (b);
 
7529
  if (cmffp == NULL)
 
7530
  {
 
7531
    return;
 
7532
  }
 
7533
  
 
7534
  if (GetValue (cmffp->all_or_percent_grp) == 2)
 
7535
  {
 
7536
    cmffp->convert_all = TRUE;
 
7537
  }
 
7538
  else
 
7539
  {
 
7540
    cmffp->convert_all = FALSE;
 
7541
  }
 
7542
  
 
7543
  cmffp->fsp = FilterSetNew();
 
7544
  cmffp->fsp->scp = DialogToPointer (cmffp->string_constraint_dlg);
 
7545
 
 
7546
  sep = GetTopSeqEntryForEntityID (cmffp->input_entityID);
 
7547
  if (sep == NULL) return;
 
7548
 
 
7549
  VisitBioseqsInSep (sep, cmffp, ConvertGappedCodingRegionsToMiscFeatBioseqCallback);
 
7550
  DeleteMarkedObjects (cmffp->input_entityID, 0, NULL);
 
7551
  ObjMgrSetDirtyFlag (cmffp->input_entityID, TRUE);
 
7552
  ObjMgrSendMsg (OM_MSG_UPDATE, cmffp->input_entityID, 0, 0);
 
7553
  Remove (cmffp->form);  
 
7554
}
 
7555
 
 
7556
extern void ConvertCodingRegionsWithInternalKnownGapToMiscFeat (IteM i)
 
7557
{
 
7558
  BaseFormPtr          bfp;
 
7559
  CDSToMiscFeatFormPtr cmffp;
 
7560
  WindoW               w;
 
7561
  GrouP                h, c;
 
7562
  ButtoN               b;
 
7563
 
 
7564
#ifdef WIN_MAC
 
7565
  bfp = currentFormDataPtr;
 
7566
#else
 
7567
  bfp = GetObjectExtra (i);
 
7568
#endif
 
7569
  if (bfp == NULL) return;
 
7570
 
 
7571
  cmffp = (CDSToMiscFeatFormPtr) MemNew (sizeof (CDSToMiscFeatFormData));
 
7572
  if (cmffp == NULL) return;
 
7573
    
 
7574
  w = FixedWindow (-50, -33, -10, -10, "Convert Coding Regions With Gaps to Misc_Feat", StdCloseWindowProc);
 
7575
  SetObjectExtra (w, cmffp, StdCleanupFormProc);
 
7576
  cmffp->form = (ForM) w;
 
7577
  cmffp->input_entityID = bfp->input_entityID;
 
7578
  h = HiddenGroup (w, -1, 0, NULL);
 
7579
  SetGroupSpacing (h, 10, 10);
 
7580
  
 
7581
  cmffp->all_or_percent_grp = HiddenGroup (h, 0, 2, NULL);
 
7582
  SetGroupSpacing (cmffp->all_or_percent_grp, 10, 10);
 
7583
  RadioButton (cmffp->all_or_percent_grp, "Convert only when internal gap covers 50% or more of the coding region");
 
7584
  RadioButton (cmffp->all_or_percent_grp, "Convert all coding regions with gaps (both terminal and internal)");
 
7585
  SetValue (cmffp->all_or_percent_grp, 1);
 
7586
  
 
7587
  cmffp->string_constraint_dlg = StringConstraintDialog (h, "Where feature text", FALSE);
 
7588
 
 
7589
  c = HiddenGroup (h, 2, 0, NULL);
 
7590
  SetGroupSpacing (c, 10, 10);
 
7591
  b = PushButton (c, "Accept", AcceptCDSToMiscFeat);
 
7592
  SetObjectExtra (b, cmffp, NULL);
 
7593
  PushButton (c, "Cancel", StdCancelButtonProc);
 
7594
  AlignObjects (ALIGN_CENTER, (HANDLE) cmffp->all_or_percent_grp,
 
7595
                              (HANDLE) cmffp->string_constraint_dlg,
 
7596
                              (HANDLE) c,
 
7597
                              NULL);
 
7598
  RealizeWindow (w);
 
7599
  Show (w);
 
7600
  Select (w);
 
7601
}
 
7602
 
 
7603
 
7084
7604
/*---------------------------------------------------------------------*/
7085
7605
/*                                                                     */
7086
7606
/* Apply_AddCDS () --                                                  */
7097
7617
  BioseqPtr          bsp;
7098
7618
  Char               ch;
7099
7619
  CdRegionPtr        crp;
 
7620
  RnaRefPtr          rrp;
7100
7621
  ValNodePtr         descr;
7101
7622
  Uint1              frame;
7102
7623
  Int2               genCode;
7116
7637
  ValNodePtr         vnp;
7117
7638
  SeqEntryPtr        parent_sep;
7118
7639
  SeqEntryPtr        gene_sep;
7119
 
  SeqFeatPtr         prot_sfp;
 
7640
  SeqFeatPtr         prot_sfp, mRNA_sfp;
7120
7641
 
7121
7642
  /* If necessary then check for duplication before adding */
7122
7643
 
7310
7831
  /* Note - this step may result in multiple coding regions being created. */
7311
7832
  AdjustCDSLocationsForGapsCallback (sfp, NULL);
7312
7833
 
 
7834
  /* if requested, also add mRNA feature */
 
7835
  if (afp->also_add_mRNA_btn != NULL && GetStatus(afp->also_add_mRNA_btn)) {
 
7836
    mRNA_sfp = CreateNewFeature (nsep, NULL, SEQFEAT_RNA, NULL); 
 
7837
    rrp = RnaRefNew ();
 
7838
    if (rrp != NULL) {
 
7839
      rrp->type = 2;
 
7840
      if (!StringHasNoText(afp->feature_details_data->protName)) {
 
7841
          rrp->ext.choice = 1;
 
7842
          rrp->ext.value.ptrvalue = StringSave (afp->feature_details_data->protName);
 
7843
      }    
 
7844
    }
 
7845
        mRNA_sfp->data.value.ptrvalue = rrp;
 
7846
    SetApplyFeatureLocation (mRNA_sfp, afp);
 
7847
    AdjustCDSLocationsForGapsCallback (mRNA_sfp, NULL);
 
7848
  }
 
7849
 
7313
7850
  /* Create a Gene ref feature on the nuc seq or segment */
7314
7851
  /* we can only create a feature where the sep->choice is 1 */
7315
7852
  if (sep->choice == 1)
8062
8599
 
8063
8600
  afp->strand_group = NULL;
8064
8601
  afp->add_to_seq_with_like_feature = NULL;
 
8602
  afp->also_add_mRNA_btn = NULL;
8065
8603
 
8066
8604
  if (type == ADD_CDS || type == ADD_RRNA || type == ADD_IMP) {
8067
8605
    /* create group to hold feature details */
8103
8641
      if (type == ADD_CDS)
8104
8642
      {
8105
8643
        afp->add_to_seq_with_like_feature = CheckBox (indexer_only_group, "Also add to sequences that already have a CDS", NULL);
 
8644
        afp->also_add_mRNA_btn = CheckBox (indexer_only_group, "Also add mRNA", NULL);
 
8645
        SetStatus (afp->also_add_mRNA_btn, FALSE);
8106
8646
      }
8107
8647
      else if (type == ADD_RRNA)
8108
8648
      {
8115
8655
      SafeSetStatus (afp->add_to_seq_with_like_feature, TRUE);
8116
8656
      AlignObjects (ALIGN_CENTER, (HANDLE) r2,
8117
8657
                                   (HANDLE) afp->add_to_seq_with_like_feature,
 
8658
                                   (HANDLE) afp->also_add_mRNA_btn,
8118
8659
                                   NULL);
8119
8660
    }
8120
8661
    else
10576
11117
  CharPtr       str_to_add;
10577
11118
  size_t        len;
10578
11119
  CharPtr       ptr;
10579
 
  CharPtr       str;
 
11120
  CharPtr       str, tmp_name;
10580
11121
  AddModInfoPtr ami;
10581
11122
  SubSourcePtr  ssp;
10582
11123
  Boolean       ok_to_add = FALSE;
10610
11151
  }
10611
11152
  
10612
11153
  onp = orp->orgname;
10613
 
  if (onp == NULL) return;
 
11154
  if (onp == NULL && ami->isOrgMod) 
 
11155
  {
 
11156
    return;
 
11157
  }
10614
11158
 
10615
11159
  str_to_add = NULL;
10616
11160
 
10646
11190
      }
10647
11191
    }
10648
11192
    influenza = FALSE;
10649
 
    if (ami->subtype == 2 && 
10650
 
        (StringICmp (orp->taxname, "Influenza A virus") == 0 ||
10651
 
        StringICmp (orp->taxname, "Influenza B virus") == 0)) {
 
11193
    if (StringICmp (orp->taxname, "Influenza A virus") == 0 ||
 
11194
        StringICmp (orp->taxname, "Influenza B virus") == 0) {
10652
11195
      influenza = TRUE;
10653
11196
    }
10654
11197
    len = StringLen (orp->taxname) + StringLen (str_to_add) + 6;
10675
11218
      if (influenza) {
10676
11219
        StringCat (str, ")");
10677
11220
      }
 
11221
      
 
11222
      if (influenza)
 
11223
      {
 
11224
        tmp_name = FixInfluenzaVirusName (str);
 
11225
        if (tmp_name != NULL)
 
11226
        {
 
11227
          str = MemFree (str);
 
11228
          str = tmp_name;
 
11229
          tmp_name = NULL;
 
11230
        }
 
11231
      }
 
11232
      
10678
11233
      SetTaxNameAndRemoveTaxRef (biop->org, str);
 
11234
      RemoveOldName (biop->org);
10679
11235
    }
10680
11236
  }
10681
11237
}
12155
12711
  }
12156
12712
}
12157
12713
 
12158
 
static Int2 GetSequinAppParam (CharPtr section, CharPtr type, CharPtr dflt, CharPtr buf, Int2 buflen)
12159
 
 
12160
 
{
12161
 
  Int2  rsult;
12162
 
 
12163
 
  rsult = GetAppParam ("SEQUINCUSTOM", section, type, NULL, buf, buflen);
12164
 
  if (rsult) return rsult;
12165
 
  rsult = GetAppParam ("SEQUIN", section, type, dflt, buf, buflen);
12166
 
  return rsult;
12167
 
}
12168
 
 
12169
12714
static FonT GetHelpFontFromConfig (CharPtr param, FonT dfault)
12170
12715
 
12171
12716
{