~ubuntu-branches/ubuntu/saucy/ncbi-tools6/saucy-proposed

« back to all changes in this revision

Viewing changes to sequin/sequin5.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2009-08-11 22:03:47 UTC
  • mfrom: (1.4.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090811220347-g4b6lzdvphvvbpiu
* New upstream release.
* debian/libncbi6.symbols: update accordingly.
* debian/control: clean up obsolete or redundant relationship declarations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   8/26/97
31
31
*
32
 
* $Revision: 6.665 $
 
32
* $Revision: 6.675 $
33
33
*
34
34
* File Description:
35
35
*
78
78
#include <tax3api.h> /* added for specific-host corrections */
79
79
#include <findrepl.h>
80
80
#include <valid.h> /* added for latloncountry conflict checking */
 
81
#include <vsmutil.h>
81
82
 
82
83
static void CommonLaunchBioseqViewer (SeqEntryPtr sep, CharPtr path, Boolean directToEditor)
83
84
 
2066
2067
}
2067
2068
 
2068
2069
 
2069
 
/*=========================================================================*/
2070
 
/*                                                                         */
2071
 
/* MergeCDS ()                                                             */
2072
 
/*                                                                         */
2073
 
/*=========================================================================*/
2074
 
 
2075
 
static void MergeCDSCallback (BioseqPtr bsp, Pointer userdata)
2076
 
{
2077
 
  SeqFeatPtr        cds, first_cds;
2078
 
  SeqMgrFeatContext fcontext;
2079
 
  Int4              left = -1, right = -1;
2080
 
  SeqLocPtr         cover_loc;
2081
 
  Boolean           partial_left = FALSE, partial_right = FALSE;
2082
 
  Uint1             strand;
2083
 
  
2084
 
  if (bsp == NULL)
2085
 
  {
2086
 
    return;
2087
 
  }
2088
 
  
2089
 
  first_cds = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_CDREGION, 0, &fcontext);
2090
 
  cds = first_cds;
2091
 
  while (NULL != cds)
2092
 
  {
2093
 
    if (left == -1 || left > fcontext.left)
2094
 
    {
2095
 
      left = fcontext.left;
2096
 
      partial_left = fcontext.partialL;
2097
 
    }
2098
 
    if (right < fcontext.right)
2099
 
    {
2100
 
      right = fcontext.right;
2101
 
      partial_right = fcontext.partialR;
2102
 
    }
2103
 
    cds = SeqMgrGetNextFeature (bsp, cds, SEQFEAT_CDREGION, 0, &fcontext);
2104
 
  }
2105
 
  if (left < 0 || right < 0)
2106
 
  {
2107
 
    return;
2108
 
  }
2109
 
  strand = SeqLocStrand (first_cds->location);
2110
 
  cover_loc = SeqLocIntNew (left, right, strand, bsp->id);
2111
 
  if (strand == Seq_strand_minus)
2112
 
  {
2113
 
        SetSeqLocPartial (cover_loc, partial_right, partial_left);
2114
 
  }
2115
 
  else
2116
 
  {
2117
 
        SetSeqLocPartial (cover_loc, partial_left, partial_right);
2118
 
  }
2119
 
 
2120
 
  cds = CreateNewFeatureOnBioseq (bsp, SEQFEAT_CDREGION, cover_loc);
2121
 
  cds->partial = (partial_left | partial_right);
2122
 
  cds->data.value.ptrvalue = AsnIoMemCopy (first_cds->data.value.ptrvalue,
2123
 
                                              (AsnReadFunc) CdRegionAsnRead,
2124
 
                                              (AsnWriteFunc) CdRegionAsnWrite);
2125
 
  RetranslateOneCDS (cds, first_cds->idx.entityID, TRUE, FALSE);
2126
 
}
2127
 
 
2128
 
extern void MergeCDS (IteM i)
2129
 
{
2130
 
  BaseFormPtr  bfp;
2131
 
  SeqEntryPtr  sep;
2132
 
  LogInfoPtr   lip;
2133
 
 
2134
 
  /* Get the top level BioseqSet */
2135
 
 
2136
 
#ifdef WIN_MAC
2137
 
  bfp = currentFormDataPtr;
2138
 
#else
2139
 
  bfp = GetObjectExtra (i);
2140
 
#endif
2141
 
 
2142
 
  if (NULL == bfp)
2143
 
    return;
2144
 
 
2145
 
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2146
 
  if (NULL == sep)
2147
 
    return;
2148
 
 
2149
 
  WatchCursor ();
2150
 
  Update ();
2151
 
 
2152
 
  lip = OpenLog ("Merge CDS Mat Peptides");
2153
 
  VisitBioseqsInSep (sep, NULL, MergeCDSCallback);
2154
 
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2155
 
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2156
 
  VisitBioseqsInSep (sep, lip, ConvertInnerCDSsToMatPeptidesCallback);
2157
 
 
2158
 
  CloseLog (lip);
2159
 
  FreeLog (lip);
2160
 
  /* Do an update and return successfully */
2161
 
 
2162
 
  DeleteMarkedObjects (bfp->input_entityID, 0, NULL);
2163
 
  ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
2164
 
  ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
2165
 
  ArrowCursor ();
2166
 
  Update ();
2167
 
 
2168
 
  return;
2169
 
}
2170
 
 
2171
2070
static Boolean ConvertImpToSpecialRNA 
2172
2071
(SeqFeatPtr sfp,
2173
2072
 Uint2      featdef_to,
2727
2626
}
2728
2627
 
2729
2628
 
 
2629
static Boolean ConvertCDSToMatPeptide (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
 
2630
{
 
2631
  return AutoConvertCDSToMiscFeat (sfp, extradata == NULL ? TRUE : !(*((BoolPtr) extradata)));
 
2632
}
 
2633
 
 
2634
 
 
2635
static Boolean ConvertMiscFeatureToCDSFunction (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
 
2636
{
 
2637
  return ConvertMiscFeatToCodingRegion (sfp);
 
2638
}
 
2639
 
2730
2640
 
2731
2641
extern EnumFieldAssoc  enum_bond_alist [];
2732
2642
extern EnumFieldAssoc  enum_site_alist [];
17145
17055
static Boolean ConvertImpToImp (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
17146
17056
static Boolean ConvertRNAToRNA (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
17147
17057
static Boolean ConvertProtToProt (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
17148
 
 
 
17058
static Boolean ConvertCDSToMatPeptide (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata);
 
17059
static Boolean ConvertMiscFeatureToCDSFunction (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata);
17149
17060
 
17150
17061
static ConvertFeatureProcsData ConvertFeaturesTable[] = {
17151
17062
  { SEQFEAT_CDREGION, FEATDEF_CDS,                SEQFEAT_RNA,    FEATDEF_ANY,
17181
17092
       "If protein feature has name, this will be saved as /product qualifier on new feature.\nIf protein feature does not have name but does have description, this will be saved as /product qualifier on new feature.\n"
17182
17093
       "EC_number values from the protein feature will be saved as /EC_number qualifiers on the new feature.\nActivity values will be saved as /function qualifiers on the new feature.\n"
17183
17094
       "Db_xref values from the protein feature will be saved as /db_xref qualifers on the new feature." },
 
17095
  { SEQFEAT_IMP,      FEATDEF_misc_feature,                SEQFEAT_CDREGION,    FEATDEF_CDS,
 
17096
       NULL, NULL, NULL, ConvertMiscFeatureToCDSFunction, NULL,
 
17097
       "Use misc_feature comment for coding region product name." },
17184
17098
  { SEQFEAT_IMP,      FEATDEF_ANY,                SEQFEAT_RNA,    FEATDEF_misc_RNA,
17185
17099
       NULL, NULL, NULL, ConvertImpToSpecialRNA, NULL,
17186
17100
       "Creates a misc_RNA.  Import feature key is discarded." },
17251
17165
  { SEQFEAT_PROT,     FEATDEF_ANY,                SEQFEAT_PROT,   FEATDEF_ANY,
17252
17166
       NULL, NULL, NULL, ConvertProtToProt, NULL,
17253
17167
       "Changes type of protein feature." },
 
17168
  { SEQFEAT_CDREGION, FEATDEF_CDS,                SEQFEAT_PROT,   FEATDEF_mat_peptide_aa,
 
17169
       NULL, NULL, NULL, ConvertCDSToMatPeptide, NULL,
 
17170
       "If coding region is overlapped by another coding region, will convert the coding region to a mat-peptide on the overlapping coding region's protein sequence, otherwise if you have checked \"Leave Original Feature\" it will create a mat-peptide with the same protein names and description on the protein sequence for the coding region." }
17254
17171
};
17255
17172
 
17256
17173
static Int4 num_convert_feature_table_lines = sizeof (ConvertFeaturesTable) / sizeof (ConvertFeatureProcsData);
18377
18294
      return FALSE;
18378
18295
    }
18379
18296
  }
 
18297
  else if (featdef_from == FEATDEF_CDS && mrfp->featdef_to == FEATDEF_mat_peptide_aa) 
 
18298
  {
 
18299
    extradata = &(mrfp->leave_original_feature);
 
18300
  }
18380
18301
 
18381
18302
  /* adjust feature list if necessary */  
18382
18303
  if (ConvertFeaturesTable[table_line_num].adjust_features != NULL) 
18442
18363
        protBsp->idx.deleteme = FALSE;
18443
18364
      }
18444
18365
    }
 
18366
    else if (sfp->data.choice == SEQFEAT_CDREGION) 
 
18367
    {
 
18368
      /* failed to convert feature, don't remove product */
 
18369
      if (protBsp != NULL)
 
18370
      {
 
18371
        protBsp->idx.deleteme = FALSE;
 
18372
      }
 
18373
    }
18445
18374
  }
18446
18375
 
18447
18376
  feat_list = ValNodeFree (feat_list);
18628
18557
  OrigFeatPtr           ofp;
18629
18558
  SeqFeatPtr            sfp;
18630
18559
  Boolean               rval = TRUE;
 
18560
  SeqEntryPtr           create_sep;
18631
18561
  
18632
18562
  if (userdata == NULL) return FALSE;
18633
18563
  
18719
18649
      {
18720
18650
        continue;
18721
18651
      }
18722
 
      sfp = CreateNewFeature (ofp->sep, NULL, ofp->sfp->data.choice, ofp->sfp);
 
18652
      if (IS_Bioseq_set (ofp->sep)) {
 
18653
        create_sep = FindNucSeqEntry (ofp->sep);
 
18654
      } else {
 
18655
        create_sep = ofp->sep;
 
18656
      }
 
18657
      sfp = CreateNewFeature (create_sep, NULL, ofp->sfp->data.choice, ofp->sfp);
18723
18658
    }
18724
18659
  }
18725
18660
  mrfp->feat_list = ValNodeFreeData (mrfp->feat_list);
29285
29220
  Show (w);   
29286
29221
}
29287
29222
 
29288
 
extern LogInfoPtr OpenLog (CharPtr display_title)
29289
 
{
29290
 
  LogInfoPtr lip;
29291
 
  
29292
 
  lip = (LogInfoPtr) MemNew (sizeof (LogInfoData));
29293
 
  if (lip == NULL)
29294
 
  {
29295
 
    return NULL;
29296
 
  }
29297
 
  TmpNam (lip->path);
29298
 
  lip->fp = FileOpen (lip->path, "w");
29299
 
  lip->data_in_log = FALSE;
29300
 
  lip->display_title = StringSave (display_title);
29301
 
  return lip;
29302
 
}
29303
 
 
29304
 
extern void CloseLog (LogInfoPtr lip)
29305
 
{
29306
 
  if (lip == NULL || lip->fp == NULL)
29307
 
  {
29308
 
    return;
29309
 
  }
29310
 
  FileClose (lip->fp);
29311
 
  lip->fp = NULL;
29312
 
  if (lip->data_in_log)
29313
 
  {
29314
 
    LaunchGeneralTextViewer (lip->path, lip->display_title);
29315
 
  }
29316
 
  FileRemove (lip->path);  
29317
 
}
29318
 
 
29319
 
extern LogInfoPtr FreeLog (LogInfoPtr lip)
29320
 
{
29321
 
  if (lip != NULL)
29322
 
  {
29323
 
    lip->display_title = MemFree (lip->display_title);
29324
 
    if (lip->fp != NULL)
29325
 
    {
29326
 
      FileClose (lip->fp);
29327
 
      lip->fp = NULL;
29328
 
      FileRemove (lip->path);
29329
 
    }
29330
 
    lip = MemFree (lip);
29331
 
  }
29332
 
  return lip;
29333
 
}
29334
 
 
29335
29223
static CharPtr GetLastLineageFromString (CharPtr lineage)
29336
29224
{
29337
29225
  CharPtr last_semicolon, lineage_start, penultimate_semicolon;
29568
29456
}
29569
29457
 
29570
29458
 
29571
 
static SeqFeatPtr GetProtFeature (BioseqPtr protbsp)
29572
 
{
29573
 
  SeqMgrFeatContext fcontext;
29574
 
  SeqAnnotPtr sap;
29575
 
  SeqFeatPtr prot_sfp;
29576
 
  ProtRefPtr prp;
29577
 
 
29578
 
  if (protbsp == NULL) return NULL;
29579
 
 
29580
 
  prot_sfp = SeqMgrGetNextFeature (protbsp, NULL, 0, FEATDEF_PROT, &fcontext);
29581
 
  if (prot_sfp == NULL) {
29582
 
    sap = protbsp->annot;
29583
 
    while (sap != NULL && prot_sfp == NULL) {
29584
 
      if (sap->type == 1) {
29585
 
        prot_sfp = sap->data;
29586
 
        while (prot_sfp != NULL
29587
 
               && (prot_sfp->data.choice != SEQFEAT_PROT
29588
 
                   || (prp = prot_sfp->data.value.ptrvalue) == NULL
29589
 
                   || prp->processed != 0)) {
29590
 
          prot_sfp = prot_sfp->next;
29591
 
        }
29592
 
      }
29593
 
      sap = sap->next;
29594
 
    }
29595
 
  }
29596
 
  return prot_sfp;
29597
 
}
29598
 
 
29599
 
 
29600
29459
static void ApplyProductName (CombineCDSPtr ccp, SeqFeatPtr new_cds)
29601
29460
{
29602
29461
  BioseqPtr         first_prot_bsp, new_prot_bsp;
29737
29596
}
29738
29597
 
29739
29598
 
29740
 
static void CombineCDSsOnBioseq (BioseqPtr bsp, Pointer userdata)
29741
 
{
29742
 
  CombineCDSPtr ccp;
29743
 
  
29744
 
  
29745
 
  if (bsp == NULL || userdata == NULL)
29746
 
  {
29747
 
    return;
29748
 
  }
29749
 
  
29750
 
  ccp = (CombineCDSPtr) userdata;
29751
 
  
29752
 
  ConvertInnerCDSsToMatPeptidesCallback (bsp, ccp->lip);
29753
 
}
 
29599
static SeqLocPtr 
 
29600
CreateProteinLoc 
 
29601
(SeqLocPtr  nuc_loc,
 
29602
 SeqFeatPtr top_cds,
 
29603
 Int4       cds_frame, 
 
29604
 BioseqPtr  prot_bsp,
 
29605
 LogInfoPtr lip)
 
29606
{
 
29607
  SeqLocPtr    prot_loc = NULL;
 
29608
  Boolean      partial5, partial3;
 
29609
  
 
29610
  if (nuc_loc == NULL || top_cds == NULL || prot_bsp == NULL
 
29611
      || top_cds->location == NULL)
 
29612
  {
 
29613
    return NULL;
 
29614
  }
 
29615
 
 
29616
  prot_loc = dnaLoc_to_aaLoc(top_cds, nuc_loc, TRUE, &cds_frame, TRUE);
 
29617
  if (prot_loc == NULL) {
 
29618
    if (lip != NULL && lip->fp != NULL)
 
29619
    {
 
29620
      fprintf (lip->fp, "Invalid coordinates for mat_peptide conversion\n");
 
29621
      lip->data_in_log = TRUE;
 
29622
    }
 
29623
    else
 
29624
    {
 
29625
      Message (MSG_ERROR, "Invalid coordinates for mat_peptide conversion");
 
29626
    }
 
29627
  } else {
 
29628
    /* set partials if necessary? */
 
29629
    CheckSeqLocForPartial (nuc_loc, &partial5, &partial3);
 
29630
    SetSeqLocPartial (prot_loc, partial5, partial3);
 
29631
  }
 
29632
 
 
29633
 
 
29634
  return prot_loc;
 
29635
}
 
29636
 
 
29637
static Boolean ConvertCDSToMatPeptideNoOverlap (SeqFeatPtr sfp, LogInfoPtr lip)
 
29638
{
 
29639
  SeqMgrFeatContext fcontext;
 
29640
 
 
29641
  if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) {
 
29642
    return FALSE;
 
29643
  }
 
29644
  if (!CreateMatPeptideFromCDS (sfp)) {
 
29645
    SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL, sfp->idx.itemID, 0, sfp, &fcontext);
 
29646
    if (lip != NULL && lip->fp != NULL) {
 
29647
      fprintf (lip->fp, "Coding region %s has no product sequence\n", fcontext.label);
 
29648
      lip->data_in_log = TRUE;
 
29649
    } else {
 
29650
      Message (MSG_ERROR, "Coding region %s has no product sequence\n", fcontext.label);
 
29651
    }
 
29652
    return FALSE;
 
29653
  } else {
 
29654
    return TRUE;
 
29655
  }
 
29656
}
 
29657
 
 
29658
 
 
29659
static void ConvertCDSToMatPeptideNoOverlapCallback (BioseqPtr bsp, Pointer userdata)
 
29660
{
 
29661
  LogInfoPtr lip;
 
29662
  SeqMgrFeatContext fcontext;
 
29663
  SeqFeatPtr sfp;
 
29664
 
 
29665
  if (bsp == NULL || ISA_aa (bsp->mol)) {
 
29666
    return;
 
29667
  }
 
29668
 
 
29669
  lip = (LogInfoPtr) userdata;
 
29670
  for (sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_CDREGION, 0, &fcontext);
 
29671
       sfp != NULL;
 
29672
       sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_CDREGION, 0, &fcontext)) {
 
29673
    ConvertCDSToMatPeptideNoOverlap (sfp, lip);
 
29674
  }
 
29675
}
 
29676
 
 
29677
 
 
29678
static void ConvertCDSToMatPeptideOverlap (SeqFeatPtr sfp, SeqFeatPtr top_cds, LogInfoPtr lip)
 
29679
{
 
29680
  SeqMgrFeatContext gene_context;
 
29681
  SeqFeatPtr gene;
 
29682
 
 
29683
  if (sfp == NULL || top_cds == NULL || sfp->data.choice != SEQFEAT_CDREGION || top_cds->data.choice != SEQFEAT_CDREGION) {
 
29684
    return;
 
29685
  }
 
29686
 
 
29687
  if (!ConvertCDSToMatPeptideForOverlappingCDS (sfp, top_cds, TRUE)) {
 
29688
    if (lip != NULL && lip->fp != NULL)
 
29689
    {
 
29690
      fprintf (lip->fp, "Invalid coordinates for mat_peptide conversion\n");
 
29691
      lip->data_in_log = TRUE;
 
29692
    }
 
29693
    else
 
29694
    {
 
29695
      Message (MSG_ERROR, "Invalid coordinates for mat_peptide conversion");
 
29696
    }
 
29697
  } else {
 
29698
    /* Mark gene with same location for deletion */
 
29699
    gene = SeqMgrGetOverlappingGene (sfp->location, &gene_context);
 
29700
    if (gene != NULL && SeqLocCompare (gene->location, sfp->location) == SLC_A_EQ_B)
 
29701
    {
 
29702
      gene->idx.deleteme = 1;
 
29703
    }
 
29704
  }
 
29705
}
 
29706
 
 
29707
 
 
29708
static void ConvertInnerCDSsToMatPeptidesCallback (BioseqPtr bsp, Pointer userdata)
 
29709
{
 
29710
  LogInfoPtr        lip;
 
29711
  SeqFeatPtr        sfp = NULL;
 
29712
  ValNodePtr        top_level_cds_list = NULL;
 
29713
  SeqMgrFeatContext context;
 
29714
  ValNodePtr        vnp;
 
29715
  SeqFeatPtr        top_cds;
 
29716
  
 
29717
  if (bsp == NULL || ! ISA_na (bsp->mol)) return;
 
29718
  lip = (LogInfoPtr) userdata;
 
29719
  
 
29720
  sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_CDREGION, 0, &context);
 
29721
  while (sfp != NULL)
 
29722
  {
 
29723
    top_cds = NULL;
 
29724
    for (vnp = top_level_cds_list;
 
29725
         vnp != NULL && top_cds == NULL; 
 
29726
         vnp = vnp->next)
 
29727
    {
 
29728
      top_cds = (SeqFeatPtr) vnp->data.ptrvalue;
 
29729
      if (top_cds != NULL)
 
29730
      {
 
29731
        if (SeqLocCompare (top_cds->location, sfp->location) != SLC_B_IN_A)
 
29732
        {
 
29733
          top_cds = NULL;
 
29734
        }
 
29735
      }
 
29736
    }
 
29737
 
 
29738
    if (top_cds == NULL)
 
29739
    {
 
29740
      /* add to list of top level CDSs */
 
29741
      ValNodeAddPointer (&top_level_cds_list, 0, sfp);
 
29742
    }
 
29743
    else
 
29744
    {
 
29745
      ConvertCDSToMatPeptideOverlap (sfp, top_cds, lip);
 
29746
    }
 
29747
    sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_CDREGION, 0, &context);
 
29748
  }
 
29749
  ValNodeFree (top_level_cds_list);
 
29750
}
 
29751
 
29754
29752
 
29755
29753
static void DoCombineCDS (ButtoN b)
29756
29754
{
29806
29804
    SeqMgrIndexFeatures (ccp->input_entityID, NULL);
29807
29805
  }
29808
29806
  
29809
 
  VisitBioseqsInSep (sep, ccp, CombineCDSsOnBioseq);
 
29807
  if (ccp->action_choice == 1 || ccp->action_choice == 2) {
 
29808
    VisitBioseqsInSep (sep, ccp->lip, ConvertInnerCDSsToMatPeptidesCallback);
 
29809
  } else {
 
29810
    VisitBioseqsInSep (sep, ccp->lip, ConvertCDSToMatPeptideNoOverlapCallback);
 
29811
  }
29810
29812
 
29811
29813
  AsnIoClose (ccp->aip);
29812
29814
  SeqEntrySetScope (old_scope);
29829
29831
  ccp = (CombineCDSPtr) GetObjectExtra (g);
29830
29832
  if (ccp == NULL) return;
29831
29833
  
29832
 
  if (GetValue (ccp->action_choice_grp) == 1)
 
29834
  if (GetValue (ccp->action_choice_grp) == 2)
 
29835
  {
 
29836
    Enable (ccp->new_cds_grp);
 
29837
  }
 
29838
  else
29833
29839
  {
29834
29840
    Disable (ccp->new_cds_grp);
29835
29841
  }
29836
 
  else
29837
 
  {
29838
 
    Enable (ccp->new_cds_grp);
29839
 
  }
29840
29842
}
29841
29843
 
29842
29844
static void EnableProdName (GrouP g)
29874
29876
  ccp = (CombineCDSPtr) MemNew (sizeof (CombineCDSData));
29875
29877
  if (ccp == NULL) return;
29876
29878
  
29877
 
  w = FixedWindow (-50, -33, -10, -10, "Combine CDS Features", StdCloseWindowProc);
 
29879
  w = FixedWindow (-50, -33, -10, -10, "Convert CDS to Mat-peptide", StdCloseWindowProc);
29878
29880
  SetObjectExtra (w, ccp, StdCleanupExtraProc);
29879
29881
  ccp->form = (ForM) w;
29880
29882
  ccp->input_entityID = bfp->input_entityID;
29882
29884
  h = HiddenGroup (w, -1, 0, NULL);
29883
29885
  SetGroupSpacing (h, 10, 10);
29884
29886
 
29885
 
  ccp->action_choice_grp = HiddenGroup (h, 0, 2, EnableNewCDSControls);
 
29887
  ccp->action_choice_grp = HiddenGroup (h, 0, 3, EnableNewCDSControls);
29886
29888
  RadioButton (ccp->action_choice_grp, "Convert inner CDSs to mat_peptides");
29887
 
  RadioButton (ccp->action_choice_grp, "AND Merge multiple CDSs into one CDS");
 
29889
  RadioButton (ccp->action_choice_grp, "Merge multiple CDSs into one CDS and convert inner CDSs to mat_peptides");
 
29890
  RadioButton (ccp->action_choice_grp, "Create mat-peptide from protein on each CDS");
29888
29891
  SetValue (ccp->action_choice_grp, 1);
29889
29892
  SetObjectExtra (ccp->action_choice_grp, ccp, NULL);
29890
29893
  
32461
32464
 
32462
32465
 
32463
32466
 
32464
 
static Int2 NewSegregateBioseqSet (BioseqSetPtr bssp, Nlm_BtnActnProc actn)
 
32467
static Int2 NewSegregateBioseqSet (BioseqSetPtr bssp, Nlm_BtnActnProc actn, ESegPage default_type)
32465
32468
{
32466
32469
  GrouP              c;
32467
32470
  SegByFieldPtr      cfp;
32611
32614
                              (HANDLE) cfp->pages[6],
32612
32615
                              NULL);
32613
32616
 
32614
 
  SetValue (cfp->seg_choice_grp, 2);
 
32617
  SetValue (cfp->seg_choice_grp, default_type);
32615
32618
 
32616
32619
  /* add select all/unselect all buttons */
32617
32620
  k = HiddenGroup (h, 3, 0, NULL);
32652
32655
  return OM_MSG_RET_OK;
32653
32656
}
32654
32657
 
32655
 
static Int2 LIBCALLBACK SegregateSetsByFieldEx (Pointer data, Nlm_BtnActnProc actn)
 
32658
static Int2 LIBCALLBACK SegregateSetsByFieldEx (Pointer data, Nlm_BtnActnProc actn, ESegPage default_type)
32656
32659
{
32657
32660
  OMProcControlPtr   ompcp;
32658
32661
 
32665
32668
    Message (MSG_ERROR, "You must select a set to segregate!");
32666
32669
    return OM_MSG_RET_ERROR;
32667
32670
  } 
32668
 
  return NewSegregateBioseqSet (ompcp->input_data, actn);
 
32671
  return NewSegregateBioseqSet (ompcp->input_data, actn, default_type);
32669
32672
}
32670
32673
 
32671
32674
 
32672
32675
extern Int2 LIBCALLBACK SegregateSetsByField (Pointer data)
32673
32676
{
32674
 
  return SegregateSetsByFieldEx (data, SegregateByField_Callback);
 
32677
  return SegregateSetsByFieldEx (data, SegregateByField_Callback, eSegPageText);
32675
32678
}
32676
32679
 
32677
32680
extern void NewSegregateBioseqSetMenuItem (IteM i)
32690
32693
  if (sep == NULL || !IS_Bioseq_set (sep)) {
32691
32694
    Message (MSG_ERROR, "This record does not have a top-levelset!");
32692
32695
  } else {
32693
 
    NewSegregateBioseqSet (FindTopLevelSetForDesktopFunction((BioseqSetPtr) sep->data.ptrvalue), SegregateByField_Callback);
 
32696
    NewSegregateBioseqSet (FindTopLevelSetForDesktopFunction((BioseqSetPtr) sep->data.ptrvalue), SegregateByField_Callback, eSegPageText);
32694
32697
  }
32695
32698
}
32696
32699
 
32766
32769
}
32767
32770
 
32768
32771
 
 
32772
/* sequesters is different from segregate - we aren't creating a permanent new set with
 
32773
 * the combined descriptors of the previous set; we're creating a temporary holding set.
 
32774
 */
32769
32775
static void SequesterCategorySeqEntries (BioseqSetPtr newset, ClickableItemPtr category)
32770
32776
{
32771
32777
  ValNodePtr vnp_item;
32772
 
  SeqEntryPtr sep, last_sep, prev_sep, remove_sep;
32773
 
  BioseqSetPtr bssp, orig_parent;
 
32778
  SeqEntryPtr sep, last_sep, prev_sep, remove_sep, set_sep, tmp_sep;
 
32779
  BioseqSetPtr bssp, orig_parent, prev_new_parent = NULL, prev_orig_parent = NULL;
32774
32780
  BioseqPtr bsp;
32775
32781
  Int4      set_pos;
32776
32782
 
32827
32833
        } else {
32828
32834
          prev_sep->next = sep->next;
32829
32835
        }
32830
 
      }
32831
 
      /* set class type if not already set */
32832
 
      if (newset->_class == BioseqseqSet_class_genbank) {
32833
 
        newset->_class = orig_parent->_class;
32834
 
      }
32835
 
 
32836
 
      /* add descriptors from the orig_parent to the new parent */
32837
 
      AddNewUniqueDescriptors (&(newset->descr), orig_parent->descr);
32838
 
 
32839
 
      /* add annotations from the orig_parent to the new parent */
32840
 
      AddNewUniqueAnnotations (&(newset->annot), orig_parent->annot);
32841
 
 
32842
 
      /* add to new parent */
32843
 
      sep->next = NULL;
 
32836
        sep->next = NULL;
 
32837
      }
 
32838
 
 
32839
      /* if this seq-entry is from the same parent as the previous one, just add this to
 
32840
       * our current placeholder.
 
32841
       */
 
32842
      if (prev_orig_parent != orig_parent) {
 
32843
        prev_new_parent = BioseqSetNew ();
 
32844
        prev_new_parent->_class = orig_parent->_class;
 
32845
        /* add descriptors from the orig_parent to the new parent */
 
32846
        AddNewUniqueDescriptors (&(prev_new_parent->descr), orig_parent->descr);
 
32847
 
 
32848
        /* add annotations from the orig_parent to the new parent */
 
32849
        AddNewUniqueAnnotations (&(prev_new_parent->annot), orig_parent->annot);
 
32850
 
 
32851
        /* add new parent to set */
 
32852
        set_sep = SeqEntryNew ();
 
32853
        set_sep->choice = 2;
 
32854
        set_sep->data.ptrvalue = prev_new_parent;
 
32855
 
 
32856
        if (newset->seq_set == NULL) {
 
32857
          newset->seq_set = set_sep;
 
32858
        } else {
 
32859
          for (tmp_sep = newset->seq_set; tmp_sep->next != NULL; tmp_sep = tmp_sep->next) {
 
32860
          }
 
32861
          tmp_sep->next = set_sep;
 
32862
        }
 
32863
        SeqMgrLinkSeqEntry (set_sep, OBJ_BIOSEQSET, newset);
 
32864
        last_sep = NULL;
 
32865
      }
 
32866
      /* add seqentry to new parent */
32844
32867
      if (last_sep == NULL) {
32845
 
        newset->seq_set = sep;
 
32868
        prev_new_parent->seq_set = sep;
32846
32869
      } else {
32847
32870
        last_sep->next = sep;
32848
32871
      }
32849
32872
      last_sep = sep;
32850
 
      SeqMgrLinkSeqEntry (sep, OBJ_BIOSEQSET, newset);
 
32873
 
 
32874
      SeqMgrLinkSeqEntry (sep, OBJ_BIOSEQSET, prev_new_parent);
32851
32875
 
32852
32876
      /* create unsequester entry */
32853
32877
      ValNodeAddPointer (&unsequester_list, 0, UnsequesterNew (sep, orig_parent, set_pos));
 
32878
 
 
32879
      prev_orig_parent = orig_parent;
32854
32880
    }
32855
32881
  } else {
32856
32882
    for (vnp_item = category->subcategories; vnp_item != NULL; vnp_item = vnp_item->next) {
33018
33044
{
33019
33045
  BaseFormPtr bfp;
33020
33046
  BioseqViewFormPtr vfp;
33021
 
  SeqEntryPtr sep, add_back_sep, next_sep;
33022
 
  BioseqSetPtr   bssp;
 
33047
  SeqEntryPtr new_parent_sep, sep, add_back_sep, next_sep;
 
33048
  BioseqSetPtr   top_bssp, bssp;
33023
33049
  UnsequesterPtr u;
33024
33050
 
33025
33051
  add_back_sep = GetTopSeqEntryForEntityID (entityID);
33029
33055
  bfp = GetBaseFormForEntityID (entityID);
33030
33056
  RemoveSeqEntryViewer (bfp->form);
33031
33057
 
33032
 
  bssp = (BioseqSetPtr) add_back_sep->data.ptrvalue;
 
33058
  /* we created a genbank set to hold the actual parent sets */
 
33059
  top_bssp = (BioseqSetPtr) add_back_sep->data.ptrvalue;
33033
33060
 
33034
33061
  /* need to process entries in seq_set in reverse, so that the set_pos will be 
33035
33062
   * correct relative to when the seq-entry was removed */
33036
 
  ValNodeReverse (&(bssp->seq_set));
33037
 
  sep = bssp->seq_set;
33038
 
 
33039
 
  while (sep != NULL) {
33040
 
    next_sep = sep->next;
33041
 
    sep->next = NULL;
33042
 
    u = GetUnsequesterForSep (sep, unsequester_list);
33043
 
    if (u == NULL || u->orig_parent == NULL) {
33044
 
      AddSepBackToSet (sep, sequester_set, bssp->descr, 0);
33045
 
    } else {
33046
 
      AddSepBackToSet (sep, u->orig_parent, bssp->descr, u->set_pos);
 
33063
  ValNodeReverse (&(top_bssp->seq_set));
 
33064
  new_parent_sep = top_bssp->seq_set;
 
33065
 
 
33066
  while (new_parent_sep != NULL) {
 
33067
    bssp = new_parent_sep->data.ptrvalue;
 
33068
    ValNodeReverse (&(bssp->seq_set));
 
33069
    sep = bssp->seq_set;
 
33070
 
 
33071
    while (sep != NULL) {
 
33072
      next_sep = sep->next;
 
33073
      sep->next = NULL;
 
33074
      u = GetUnsequesterForSep (sep, unsequester_list);
 
33075
      if (u == NULL || u->orig_parent == NULL) {
 
33076
        AddSepBackToSet (sep, sequester_set, bssp->descr, 0);
 
33077
      } else {
 
33078
        AddSepBackToSet (sep, u->orig_parent, bssp->descr, u->set_pos);
 
33079
      }
 
33080
      sep = next_sep;
33047
33081
    }
33048
 
    sep = next_sep;
 
33082
    bssp->seq_set = NULL;
 
33083
    new_parent_sep = new_parent_sep->next;
33049
33084
  }
33050
33085
 
33051
33086
  ObjMgrDelete (OBJ_SEQENTRY, add_back_sep);
33052
 
  bssp->seq_set = NULL;
33053
 
  bssp->idx.deleteme = TRUE;
 
33087
  top_bssp->seq_set = NULL;
 
33088
  top_bssp->idx.deleteme = TRUE;
33054
33089
  DeleteMarkedObjects (entityID, 0, NULL);
33055
33090
 
33056
33091
  DeleteMarkedObjects (sequester_set->idx.entityID, 0, NULL);
33220
33255
  }
33221
33256
}
33222
33257
 
 
33258
NLM_EXTERN Boolean OkToSequester (void)
 
33259
{
 
33260
  if (unsequester_list != NULL || sequester_set != NULL) {
 
33261
    return FALSE;
 
33262
  } else {
 
33263
    return TRUE;
 
33264
  }
 
33265
}
 
33266
 
 
33267
 
 
33268
NLM_EXTERN void LIBCALLBACK SequesterSequenceList (Uint2 entityID, ValNodePtr bsp_list)
 
33269
{
 
33270
  SeqEntryPtr sep;
 
33271
  BioseqSetPtr bssp, new_set;
 
33272
  ClickableItemData cid;
 
33273
  ObjMgrDataPtr  omdptop;
 
33274
  ObjMgrData     omdata;
 
33275
  Uint2          parenttype;
 
33276
  Pointer        parentptr;
 
33277
  Uint2          new_entityID;
 
33278
  FormMessageFunc old_message_handler;
 
33279
  BaseFormPtr     bfp;
 
33280
  BioseqViewFormPtr vfp;
 
33281
  SeqEntryPtr       pulled_sep;
 
33282
 
 
33283
  if (bsp_list == NULL) {
 
33284
    return;
 
33285
  }
 
33286
 
 
33287
  if (unsequester_list != NULL || sequester_set != NULL) {
 
33288
    Message (MSG_ERROR, "You are already sequestering a set.  You cannot sequester until you have restored these sequences to the original set.");
 
33289
    return;
 
33290
  }
 
33291
 
 
33292
  sep = GetTopSeqEntryForEntityID (entityID);
 
33293
  if (sep == NULL || !IS_Bioseq_set (sep)) {
 
33294
    Message (MSG_ERROR, "This record does not have a top-levelset!");
 
33295
    return;
 
33296
  }
 
33297
 
 
33298
  bssp = FindTopLevelSetForDesktopFunction((BioseqSetPtr) sep->data.ptrvalue);
 
33299
  if (bssp == NULL) {
 
33300
    Message (MSG_ERROR, "Unable to find top level set");
 
33301
    return;
 
33302
  }
 
33303
 
 
33304
  WriteTheEntityID (entityID, SEQUESTER_BACKUP_FILE, FALSE);
 
33305
  sequester_set = bssp;
 
33306
 
 
33307
  /* create a new set with just the chosen sequences */
 
33308
  SaveSeqEntryObjMgrData (sep, &omdptop, &omdata);
 
33309
  GetSeqEntryParent (sep, &parentptr, &parenttype);
 
33310
 
 
33311
  new_set = BioseqSetNew ();
 
33312
  new_set->_class = BioseqseqSet_class_genbank;
 
33313
 
 
33314
  MemSet (&cid, 0, sizeof (ClickableItemData));
 
33315
  cid.chosen = TRUE;
 
33316
  cid.item_list = bsp_list;
 
33317
  SequesterCategorySeqEntries (new_set, &cid);
 
33318
 
 
33319
  RestoreSeqEntryObjMgrData (sep, omdptop, &omdata); 
 
33320
  DeleteMarkedObjects (entityID, 0, NULL);
 
33321
  ObjMgrSetDirtyFlag (entityID, TRUE);
 
33322
  ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
33323
 
 
33324
  pulled_sep = SeqEntryNew ();
 
33325
  pulled_sep->choice = 2;
 
33326
  pulled_sep->data.ptrvalue = new_set;
 
33327
  SeqMgrLinkSeqEntry (pulled_sep, 0, NULL);
 
33328
  
 
33329
  new_entityID = ObjMgrRegister (OBJ_SEQENTRY, pulled_sep);
 
33330
  seqviewprocs.filepath = NULL;
 
33331
  seqviewprocs.forceSeparateViewer = TRUE;
 
33332
  old_message_handler = seqviewprocs.handleMessages;
 
33333
  seqviewprocs.handleMessages = SequesterFormMessage;
 
33334
 
 
33335
 
 
33336
  SeqEntrySetScope (NULL);
 
33337
  GatherProcLaunch (OMPROC_VIEW, FALSE, new_entityID, 1,
 
33338
                              OBJ_BIOSEQ, 0, 0, OBJ_BIOSEQ, 0);
 
33339
 
 
33340
  seqviewprocs.handleMessages = old_message_handler;
 
33341
 
 
33342
  /* hide viewer with the remaining sequences */
 
33343
  bfp = GetBaseFormForEntityID (entityID);
 
33344
  if (bfp != NULL) {
 
33345
    Hide (bfp->form);
 
33346
    vfp = (BioseqViewFormPtr) bfp;
 
33347
    Hide (vfp->toolForm);
 
33348
  }
 
33349
 
 
33350
  /* get rid of existing validator window, replace with validator for new sequences */
 
33351
  FreeValidateWindow ();
 
33352
  bfp = GetBaseFormForEntityID (new_entityID);
 
33353
  ValSeqEntryForm (bfp->form);
 
33354
}
 
33355
 
33223
33356
 
33224
33357
extern Int2 LIBCALLBACK SequesterSequences (Pointer data)
33225
33358
{
33226
33359
  /* note - in future, will need to make sequester dialog modal. */
33227
 
  return SegregateSetsByFieldEx (data, SequesterSets);
 
33360
  return SegregateSetsByFieldEx (data, SequesterSets, eSegPageId);
33228
33361
}
33229
33362
 
33230
33363
 
33244
33377
  if (sep == NULL || !IS_Bioseq_set (sep)) {
33245
33378
    Message (MSG_ERROR, "This record does not have a top-levelset!");
33246
33379
  } else {
33247
 
    NewSegregateBioseqSet (FindTopLevelSetForDesktopFunction((BioseqSetPtr) sep->data.ptrvalue), SequesterSets);
 
33380
    NewSegregateBioseqSet (FindTopLevelSetForDesktopFunction((BioseqSetPtr) sep->data.ptrvalue), SequesterSets, eSegPageId);
33248
33381
  }
33249
33382
}
33250
33383
 
37343
37476
}
37344
37477
 
37345
37478
 
 
37479
static Pointer HasBarcodeKeyword (Uint1 data_choice, Pointer data, Pointer metadata)
 
37480
{
 
37481
  SeqDescrPtr sdp;
 
37482
  SeqMgrDescContext context;
 
37483
  GBBlockPtr gb;
 
37484
  ValNodePtr vnp;
 
37485
  Boolean rval = FALSE;
 
37486
 
 
37487
  BarcodeTestResultsPtr res = (BarcodeTestResultsPtr) data;
 
37488
  if (res != NULL && res->bsp != NULL) {
 
37489
    for (sdp = SeqMgrGetNextDescriptor (res->bsp, NULL, Seq_descr_genbank, &context);
 
37490
         sdp != NULL && !rval;
 
37491
         sdp = SeqMgrGetNextDescriptor (res->bsp, sdp, Seq_descr_genbank, &context)) {
 
37492
      gb = (GBBlockPtr) sdp->data.ptrvalue;
 
37493
      if (gb != NULL) {
 
37494
        for (vnp = gb->keywords; vnp != NULL && !rval; vnp = vnp->next) {
 
37495
          if (StringCmp (vnp->data.ptrvalue, "BARCODE") == 0) {
 
37496
            rval = TRUE;
 
37497
          }
 
37498
        }
 
37499
      }
 
37500
    }
 
37501
  }
 
37502
  if (rval) {
 
37503
    return StringSave ("TRUE");
 
37504
  } else {
 
37505
    return NULL;
 
37506
  }
 
37507
}
 
37508
 
 
37509
 
 
37510
 
37346
37511
static Int4 BarcodeFormatBarcodeID (ColPtr col, CharPtr name)
37347
37512
{
37348
37513
  if (col == NULL) return 0;
37405
37570
  { "Country", NULL, NULL, GetBarcodeTestCountryResult, NULL, BulkFreeSimpleText, NULL, BulkFormatTrueFalse, BulkDrawTrueFalse, NULL, BulkSimpleTextCopy }, 
37406
37571
  { "Voucher", NULL, NULL, GetBarcodeTestSpecimenVoucherResult, NULL, BulkFreeSimpleText, NULL, BulkFormatTrueFalse, BulkDrawTrueFalse, NULL, BulkSimpleTextCopy }, 
37407
37572
  { "Percent Ns", NULL, NULL, GetBarcodeTestPercentNsResult, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BarcodeFormatPercentN, NULL, NULL, BulkSimpleTextCopy }, 
 
37573
  { "Has BARCODE Keyword", NULL, NULL, HasBarcodeKeyword, NULL, BulkFreeSimpleText, NULL, BulkFormatTrueFalse, BulkDrawTrueFalse, NULL, BulkSimpleTextCopy }, 
37408
37574
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
37409
37575
 
37410
37576
static void NavigateToBarcodeTestResultBioseq (ValNodePtr object, Pointer userdata)