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

« back to all changes in this revision

Viewing changes to sequin/sequin1.c

Tags: upstream-6.1.20080302
ImportĀ upstreamĀ versionĀ 6.1.20080302

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.622 $
 
32
* $Revision: 6.653 $
33
33
*
34
34
* File Description: 
35
35
*
92
92
#include <tax3api.h>
93
93
#include <validerr.h>
94
94
#include <algo/blast/api/blast_api.h>
 
95
#include <findrepl.h>
95
96
 
96
97
/* USE_SMARTNET */
97
98
#ifdef USE_SMARTNET
130
131
#include <Gestalt.h>
131
132
#endif
132
133
 
133
 
#define SEQ_APP_VER "7.70"
 
134
#define SEQ_APP_VER "8.03"
134
135
 
135
136
#ifndef CODECENTER
136
137
static char* sequin_version_binary = "Sequin Indexer Services Version " SEQ_APP_VER " " __DATE__ " " __TIME__;
147
148
Boolean  useDesktop = FALSE;
148
149
Boolean  useEntrez = FALSE;
149
150
Boolean  useSeqFetch = FALSE;
 
151
Boolean  useIdLookup = FALSE;
150
152
Boolean  useLocal = FALSE;
151
153
Boolean  useBlast = FALSE;
152
154
Boolean  useMedarch = FALSE;
306
308
static Int4 SMWriteBioseqObj(VoidPtr bio_data, SMUserDataPtr sm_usr_data, 
307
309
                             VoidPtr data);
308
310
static Int4 SMReadBioseqObj(VoidPtr data, CharPtr buffer, 
309
 
                            Int4 length, Int4 fd);
 
311
                            Int4 length, void* fd);
310
312
#define SMART_KEY 1313
311
313
#define DUMB_KEY 1314
312
314
#endif
391
393
  }
392
394
}
393
395
 
 
396
static void TaxonValidate (SeqEntryPtr sep, ValidStructPtr vsp);
 
397
 
 
398
 
394
399
static Boolean OkayToWriteTheEntity (Uint2 entityID, ForM f)
395
400
 
396
401
{
406
411
  if (entityID < 1) return FALSE;
407
412
  sep = GetTopSeqEntryForEntityID (entityID);
408
413
  if (sep == NULL) return FALSE;
 
414
 
 
415
  if (!FixSpecialCharacters (entityID)) return FALSE;
 
416
 
409
417
  if (GetSequinAppParam ("PREFERENCES", "ASKBEFOREVALIDATE", NULL, str, sizeof (str))) {
410
418
    if (StringICmp (str, "TRUE") == 0) {
411
419
      if (! (subtoolMode ||smartnetMode || backupMode) ) {
424
432
    }
425
433
    if (indexerVersion) {
426
434
      vsp->alwaysRequireIsoJTA = TRUE;
 
435
      if (smartnetMode) {
 
436
        vsp->farFetchCDSproducts = TRUE;
 
437
        vsp->farFetchMRNAproducts = TRUE;
 
438
      }
427
439
    }
428
440
    oldErrSev = ErrSetMessageLevel (SEV_MAX);
429
441
    vsp->validateAlignments = TRUE;
430
442
    vsp->alignFindRemoteBsp = TRUE;
431
443
    vsp->doSeqHistAssembly = FALSE;
 
444
    if (smartnetMode) {
 
445
      vsp->doSeqHistAssembly = TRUE;
 
446
      vsp->farIDsInAlignments = TRUE;
 
447
      if (useEntrez) {
 
448
        /*
 
449
        LookupFarSeqIDs (sep, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE);
 
450
        vsp->inferenceAccnCheck = TRUE;
 
451
        */
 
452
      }
 
453
      vsp->testLatLonSubregion = testLatLonSubregion;
 
454
      vsp->strictLatLonCountry = strictLatLonCountry;
 
455
    }
432
456
    for (j = 0; j < 6; j++) {
433
457
      vsp->errors [j] = 0;
434
458
    }
435
459
    ValidateSeqEntry (sep, vsp);
 
460
    if (indexerVersion && useEntrez) {
 
461
      TaxonValidate (sep, vsp);
 
462
    }
436
463
    ErrSetMessageLevel (oldErrSev);
437
464
    ErrClear ();
438
465
    ErrShow ();
1269
1296
        
1270
1297
        omudp = ObjMgrGetUserData(bfp->input_entityID, 0, 0, SMART_KEY);
1271
1298
        if (omudp == NULL) return;
 
1299
 
 
1300
        /* for now set dirty flag to force validation in OkayToWriteTheEntity */
 
1301
        ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
1302
 
1272
1303
        omdp = ObjMgrGetData (bfp->input_entityID);
1273
1304
 
1274
1305
        sm_usr_data = (SMUserDataPtr) omudp->userdata.ptrvalue;
1558
1589
      vsp->errors [j] = 0;
1559
1590
    }
1560
1591
    ValidateSeqEntry (sep, vsp);
 
1592
    if (indexerVersion && useEntrez) {
 
1593
      TaxonValidate (sep, vsp);
 
1594
    }
1561
1595
    ErrSetMessageLevel (oldErrSev);
1562
1596
    ErrClear ();
1563
1597
    ErrShow ();
1603
1637
          }
1604
1638
          vsp->errfunc = ValidErrCallback;
1605
1639
          ValidateSeqEntry (sep, vsp);
 
1640
          if (indexerVersion && useEntrez) {
 
1641
            TaxonValidate (sep, vsp);
 
1642
          }
1606
1643
          ErrSetMessageLevel (oldErrSev);
1607
1644
          ErrSetHandler (oldErrHook);
1608
1645
          ErrClear ();
1828
1865
{
1829
1866
  ValNodePtr  bad_biop_list, vnp;
1830
1867
  ObjValNodePtr ovp;
 
1868
  BioSourcePtr  biop;
 
1869
  OrgModPtr     mod;
1831
1870
 
1832
 
  bad_biop_list = Taxon3CheckSpecificHostInSeqEntry (sep, TRUE);
 
1871
  bad_biop_list = Taxon3CheckSpecificHostInSeqEntry (sep, TRUE, FALSE);
1833
1872
 
1834
1873
  for (vnp = bad_biop_list; vnp != NULL; vnp = vnp->next)
1835
1874
  {
1837
1876
    vsp->descr = NULL;
1838
1877
    vsp->bsp = NULL;
1839
1878
    vsp->bssp = NULL;
 
1879
    biop = NULL;
 
1880
    mod = NULL;
1840
1881
 
1841
1882
    if (vnp->choice == OBJ_SEQFEAT)
1842
1883
    {
1852
1893
      {
1853
1894
        vsp->bssp = vsp->sfp->idx.parentptr;        
1854
1895
      }
 
1896
      biop = (BioSourcePtr) vsp->sfp->data.value.ptrvalue;
1855
1897
    } 
1856
1898
    else if (vnp->choice == OBJ_SEQDESC)
1857
1899
    {
1872
1914
          vsp->bssp = ovp->idx.parentptr;        
1873
1915
        }
1874
1916
      }
 
1917
      biop = vsp->descr->data.ptrvalue;
1875
1918
    }
1876
1919
    
1877
 
    ValidErr (vsp, SEV_WARNING, ERR_SEQ_DESCR_TaxonomyLookupProblem, "Invalid value for specific host");
 
1920
    if (biop != NULL && biop->org != NULL && biop->org->orgname != NULL)
 
1921
    {
 
1922
      mod = biop->org->orgname->mod;
 
1923
      while (mod != NULL && mod->subtype != ORGMOD_nat_host)
 
1924
      {
 
1925
        mod = mod->next;
 
1926
      }
 
1927
      if (mod != NULL)
 
1928
      {      
 
1929
        ValidErr (vsp, SEV_WARNING, ERR_SEQ_DESCR_BadSpecificHost, "Invalid value for specific host: %s", mod->subname);
 
1930
      }
 
1931
    }
1878
1932
  }
1879
1933
  bad_biop_list = ValNodeFree (bad_biop_list);
1880
1934
}
1881
1935
 
 
1936
static Boolean log_tax_asn = FALSE;
 
1937
static Boolean log_tax_set = FALSE;
1882
1938
 
1883
1939
static void TaxonValidate (SeqEntryPtr sep, ValidStructPtr vsp)
1884
1940
 
1930
1986
    last = vnp2;
1931
1987
  }
1932
1988
 
 
1989
#ifdef OS_UNIX
 
1990
  if (! log_tax_set) {
 
1991
    str = (CharPtr) getenv ("LOG_TAX_ASN");
 
1992
    if (StringDoesHaveText (str)) {
 
1993
      if (StringICmp (str, "TRUE") == 0) {
 
1994
        log_tax_asn = TRUE;
 
1995
      }
 
1996
    }
 
1997
    log_tax_set = TRUE;
 
1998
  }
 
1999
#endif
 
2000
 
1933
2001
  sev = ErrSetMessageLevel (SEV_WARNING);
 
2002
  if (log_tax_asn) {
 
2003
    LaunchAsnTextViewer ((Pointer) t3rq, (AsnWriteFunc) Taxon3RequestAsnWrite, "tax3 request");
 
2004
  }
1934
2005
  t3ry = Tax3SynchronousQuery (t3rq);
1935
2006
  ErrSetMessageLevel (sev);
1936
2007
  Taxon3RequestFree (t3rq);
1937
2008
  if (t3ry == NULL) return;
 
2009
  if (log_tax_asn) {
 
2010
    LaunchAsnTextViewer ((Pointer) t3ry, (AsnWriteFunc) Taxon3ReplyAsnWrite, "tax3 result");
 
2011
  }
1938
2012
 
1939
2013
  for (trp = t3ry->reply, vnp = srclist.head;
1940
2014
       trp != NULL && vnp != NULL;
2038
2112
  ReportBadSpecificHostValues (sep, vsp);
2039
2113
}
2040
2114
 
2041
 
static void ValSeqEntryFormEx (ForM f, Boolean doAligns, Int2 limit)
 
2115
static void ValSeqEntryFormEx (ForM f, Boolean doAligns, Int2 limit, Boolean inferenceAccnCheck)
2042
2116
 
2043
2117
{
2044
2118
  Boolean         allRawOrSeg = TRUE;
2102
2176
            }
2103
2177
          }
2104
2178
        }
2105
 
        if (useEntrez) {
 
2179
        if (useEntrez && inferenceAccnCheck) {
2106
2180
          LookupFarSeqIDs (sep, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE);
2107
2181
          vsp->inferenceAccnCheck = TRUE;
2108
2182
        }
2142
2216
  }
2143
2217
}
2144
2218
 
 
2219
static void CountInfAccnVer (SeqFeatPtr sfp, Pointer userdata)
 
2220
 
 
2221
{
 
2222
  Int4Ptr    countP;
 
2223
  GBQualPtr  gbq;
 
2224
 
 
2225
  if (sfp == NULL || userdata == NULL) return;
 
2226
  countP = (Int4Ptr) userdata;
 
2227
 
 
2228
  for (gbq = sfp->qual; gbq != NULL; gbq = gbq->next) {
 
2229
    if (StringICmp (gbq->qual, "inference") == 0) {
 
2230
      (*countP)++;
 
2231
    }
 
2232
  }
 
2233
}
 
2234
 
 
2235
static Boolean SmallInferenceAccnVer (ForM f)
 
2236
 
 
2237
{
 
2238
  BaseFormPtr  bfp;
 
2239
  Int4         count = 0;
 
2240
  SeqEntryPtr  sep;
 
2241
 
 
2242
  bfp = (BaseFormPtr) GetObjectExtra (f);
 
2243
  if (bfp == NULL) return FALSE;
 
2244
 
 
2245
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
2246
  if (sep == NULL) return FALSE;
 
2247
 
 
2248
  VisitFeaturesInSep (sep, (Pointer) &count, CountInfAccnVer);
 
2249
 
 
2250
  if (count < 100) return TRUE;
 
2251
 
 
2252
  if (indexerVersion) {
 
2253
    Message (MSG_POST, "Validation skipping %ld inference accession.version tests",
 
2254
             (long) count);
 
2255
  }
 
2256
 
 
2257
  return FALSE;
 
2258
}
 
2259
 
2145
2260
extern void ValSeqEntryForm (ForM f)
2146
2261
 
2147
2262
{
2148
 
  ValSeqEntryFormEx (f, TRUE, VALIDATE_ALL);
 
2263
  Boolean  inferenceAccnCheck;
 
2264
 
 
2265
  inferenceAccnCheck = SmallInferenceAccnVer (f);
 
2266
  ValSeqEntryFormEx (f, TRUE, VALIDATE_ALL, inferenceAccnCheck);
2149
2267
}
2150
2268
 
2151
2269
static void ValSeqEntryProc (IteM i)
2152
2270
 
2153
2271
{
2154
2272
  BaseFormPtr  bfp;
 
2273
  Boolean      inferenceAccnCheck;
2155
2274
 
2156
2275
#ifdef WIN_MAC
2157
2276
  bfp = (BaseFormPtr) currentFormDataPtr;
2159
2278
  bfp = (BaseFormPtr) GetObjectExtra (i);
2160
2279
#endif
2161
2280
  if (bfp != NULL) {
2162
 
    ValSeqEntryForm (bfp->form);
 
2281
    inferenceAccnCheck = SmallInferenceAccnVer (bfp->form);
 
2282
    ValSeqEntryFormEx (bfp->form, TRUE, VALIDATE_ALL, inferenceAccnCheck);
2163
2283
  }
2164
2284
}
2165
2285
 
2174
2294
  bfp = (BaseFormPtr) GetObjectExtra (i);
2175
2295
#endif
2176
2296
  if (bfp != NULL) {
2177
 
    ValSeqEntryFormEx (bfp->form, FALSE, VALIDATE_ALL);
 
2297
    ValSeqEntryFormEx (bfp->form, FALSE, VALIDATE_ALL, FALSE);
 
2298
  }
 
2299
}
 
2300
 
 
2301
static void ValSeqEntryProcInfAccn (IteM i)
 
2302
 
 
2303
{
 
2304
  BaseFormPtr  bfp;
 
2305
 
 
2306
#ifdef WIN_MAC
 
2307
  bfp = (BaseFormPtr) currentFormDataPtr;
 
2308
#else
 
2309
  bfp = (BaseFormPtr) GetObjectExtra (i);
 
2310
#endif
 
2311
  if (bfp != NULL) {
 
2312
    ValSeqEntryFormEx (bfp->form, FALSE, VALIDATE_ALL, TRUE);
2178
2313
  }
2179
2314
}
2180
2315
 
2189
2324
  bfp = (BaseFormPtr) GetObjectExtra (i);
2190
2325
#endif
2191
2326
  if (bfp != NULL) {
2192
 
    ValSeqEntryFormEx (bfp->form, FALSE, limit);
 
2327
    ValSeqEntryFormEx (bfp->form, FALSE, limit, FALSE);
2193
2328
  }
2194
2329
}
2195
2330
 
4021
4156
const char *nucleotide_alphabet = "ABCDGHKMRSTUVWYabcdghkmrstuvwy";
4022
4157
const char *protein_alphabet = "ABCDEFGHIKLMPQRSTUVWXYZabcdefghiklmpqrstuvwxyz";
4023
4158
 
4024
 
extern TSequenceInfoPtr GetDefaultSequenceInfo ()
 
4159
extern TSequenceInfoPtr GetDefaultSequenceInfo (void)
4025
4160
{
4026
4161
  TSequenceInfoPtr sequence_info = SequenceInfoNew();
4027
4162
 
5661
5796
  }
5662
5797
}
5663
5798
 
5664
 
extern SeqEntryPtr RestoreFromFile (CharPtr path);
5665
 
extern SeqEntryPtr RestoreFromFile (CharPtr path)
5666
 
 
5667
 
{
5668
 
  BioseqPtr     bsp;
5669
 
  BioseqSetPtr  bssp;
5670
 
  Pointer       dataptr;
5671
 
  Uint2         datatype;
5672
 
  Uint2         entityID;
5673
 
  SeqEntryPtr   rsult;
5674
 
  SeqEntryPtr   sep;
5675
 
 
5676
 
  rsult = NULL;
5677
 
  if (path != NULL && path [0] != '\0') {
5678
 
    dataptr = ObjMgrGenericAsnTextFileRead (path, &datatype, &entityID);
5679
 
    if (dataptr != NULL && entityID > 0) {
5680
 
      if (datatype == OBJ_SEQSUB || datatype == OBJ_SEQENTRY ||
5681
 
          datatype == OBJ_BIOSEQ || datatype == OBJ_BIOSEQSET) {
5682
 
        WatchCursor ();
5683
 
        sep = GetTopSeqEntryForEntityID (entityID);
5684
 
        if (sep == NULL) {
5685
 
          sep = SeqEntryNew ();
5686
 
          if (sep != NULL) {
5687
 
            if (datatype == OBJ_BIOSEQ) {
5688
 
              bsp = (BioseqPtr) dataptr;
5689
 
              sep->choice = 1;
5690
 
              sep->data.ptrvalue = bsp;
5691
 
              SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) bsp, sep);
5692
 
            } else if (datatype == OBJ_BIOSEQSET) {
5693
 
              bssp = (BioseqSetPtr) dataptr;
5694
 
              sep->choice = 2;
5695
 
              sep->data.ptrvalue = bssp;
5696
 
              SeqMgrSeqEntry (SM_BIOSEQSET, (Pointer) bssp, sep);
5697
 
            } else {
5698
 
              sep = SeqEntryFree (sep);
5699
 
            }
5700
 
          }
5701
 
          sep = GetTopSeqEntryForEntityID (entityID);
5702
 
        }
5703
 
        if (sep != NULL) {
5704
 
          rsult = SeqEntryNew ();
5705
 
          if (rsult != NULL) {
5706
 
            rsult->choice = sep->choice;
5707
 
            rsult->data.ptrvalue = sep->data.ptrvalue;
5708
 
            sep->data.ptrvalue = NULL;
5709
 
            if (datatype == OBJ_SEQSUB) {
5710
 
              SeqSubmitFree ((SeqSubmitPtr) dataptr);
5711
 
            } else {
5712
 
              SeqEntryFree (sep);
5713
 
            }
5714
 
            /*Message (MSG_OK, "Call new object manager free function");*/
5715
 
          }
5716
 
        }
5717
 
        ArrowCursor ();
5718
 
      }
5719
 
      /*
5720
 
      ObjMgrDelete (entityID);
5721
 
      */
5722
 
    }
5723
 
  }
5724
 
  return rsult;
5725
 
}
5726
5799
 
5727
5800
static void RestoreSeqEntryProc (IteM i)
5728
5801
 
5729
5802
{
5730
 
  SeqEntryPtr  currsep;
5731
5803
  BaseFormPtr  bfp;
5732
 
  SeqEntryPtr  oldsep;
5733
5804
  Char         path [PATH_MAX];
 
5805
  Uint2        new_entityID;
5734
5806
 
5735
5807
#ifdef WIN_MAC
5736
5808
  bfp = currentFormDataPtr;
5739
5811
#endif
5740
5812
  if (bfp != NULL && bfp->input_itemtype == OBJ_BIOSEQ) {
5741
5813
    if (GetInputFileName (path, sizeof (path), "", "TEXT")) {
5742
 
      SeqEntrySetScope (NULL);
5743
 
      oldsep = RestoreFromFile (path);
5744
 
      currsep = GetTopSeqEntryForEntityID (bfp->input_entityID);
5745
 
      ReplaceSeqEntryWithSeqEntry (currsep, oldsep, TRUE);
5746
 
      SeqEntrySetScope (NULL);
5747
 
      bfp->input_entityID = ObjMgrGetEntityIDForChoice (currsep);
5748
 
      ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
5749
 
      ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
5814
      new_entityID = RestoreEntityIDFromFile (path, bfp->input_entityID);
 
5815
      if (new_entityID != 0) {
 
5816
        bfp->input_entityID = new_entityID;
 
5817
        ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
 
5818
        ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
 
5819
      }
5750
5820
    }
5751
5821
  }
5752
5822
}
6686
6756
      SetObjectExtra (i, bfp, NULL);
6687
6757
      i = CommandItem (sub, "Validate no Alignments/ A", ValSeqEntryProcNoAln);
6688
6758
      SetObjectExtra (i, bfp, NULL);
 
6759
      i = CommandItem (sub, "Validate check Inference", ValSeqEntryProcInfAccn);
 
6760
      SetObjectExtra (i, bfp, NULL);
6689
6761
      SeparatorItem (sub);
6690
6762
      i = CommandItem (sub, "Validate Inst", ValSeqEntryProcInst);
6691
6763
      SetObjectExtra (i, bfp, NULL);
7378
7450
  if (bfp != NULL) {
7379
7451
    switch (mssg) {
7380
7452
      case VIB_MSG_SAVE :
7381
 
        SaveSeqSubmitProc (bfp, FALSE);
 
7453
        if (FixSpecialCharacters (bfp->input_entityID))
 
7454
        {
 
7455
          SaveSeqSubmitProc (bfp, FALSE);
 
7456
        }
7382
7457
        break;
7383
7458
      case VIB_MSG_SAVE_AS :
7384
 
        SaveSeqSubmitProc (bfp, TRUE);
 
7459
        if (FixSpecialCharacters (bfp->input_entityID))
 
7460
        {
 
7461
          SaveSeqSubmitProc (bfp, TRUE);
 
7462
        }
7385
7463
        break;
7386
7464
      case VIB_MSG_CLOSE :
7387
7465
        CloseProc (bfp);
9077
9155
    validateMenu = SubMenu (m, "Validate");
9078
9156
    CommandItem (validateMenu, "Validate Record/ V", ValSeqEntryProc);
9079
9157
    CommandItem (validateMenu, "Validate no Alignments", ValSeqEntryProcNoAln);
 
9158
    CommandItem (validateMenu, "Validate check Inference", ValSeqEntryProcInfAccn);
9080
9159
    SeparatorItem (validateMenu);
9081
9160
    CommandItem (validateMenu, "Validate Inst", ValSeqEntryProcInst);
9082
9161
    CommandItem (validateMenu, "Validate Hist", ValSeqEntryProcHist);
9804
9883
  useDesktop = FALSE;
9805
9884
  useEntrez = FALSE;
9806
9885
  useLocal = FALSE;
 
9886
  useIdLookup = FALSE;
9807
9887
  useBlast = FALSE;
9808
9888
  useMedarch = FALSE;
9809
9889
  newMedarch = FALSE;
9820
9900
  useDesktop = TRUE;
9821
9901
  useEntrez = TRUE;
9822
9902
  useLocal = TRUE;
 
9903
  useIdLookup = TRUE;
9823
9904
  useBlast = TRUE;
9824
9905
  useMedarch = TRUE;
9825
9906
  newMedarch = TRUE;
9833
9914
      useDesktop = TRUE;
9834
9915
      useEntrez = TRUE;
9835
9916
      useLocal = TRUE;
 
9917
      useIdLookup = TRUE;
9836
9918
      useBlast = TRUE;
9837
9919
      useMedarch = TRUE;
9838
9920
      newMedarch = TRUE;
9845
9927
  useDesktop = TRUE;
9846
9928
  useEntrez = TRUE;
9847
9929
  useLocal = TRUE;
 
9930
  useIdLookup = TRUE;
9848
9931
  useBlast = TRUE;
9849
9932
  useMedarch = TRUE;
9850
9933
  newMedarch = TRUE;
9856
9939
      useDesktop = TRUE;
9857
9940
      useEntrez = TRUE;
9858
9941
      useLocal = TRUE;
 
9942
      useIdLookup = TRUE;
9859
9943
      useBlast = TRUE;
9860
9944
      useMedarch = TRUE;
9861
9945
      newMedarch = TRUE;
9939
10023
    if (StringICmp (str, "TRUE") == 0) {
9940
10024
      allowDownload = FALSE;
9941
10025
      useEntrez = FALSE;
 
10026
      useMedarch = FALSE;
 
10027
      useTaxon = FALSE;
 
10028
    }
 
10029
  }
 
10030
 
 
10031
  useSeqFetch = useEntrez;
 
10032
 
 
10033
  if (GetSequinAppParam ("SETTINGS", "SUPPRESSSEQFETCH", NULL, str, sizeof (str))) {
 
10034
    if (StringICmp (str, "TRUE") == 0) {
 
10035
      useSeqFetch = FALSE;
 
10036
    }
 
10037
  }
 
10038
 
 
10039
  if (GetSequinAppParam ("SETTINGS", "SUPPRESSIDLOOKUP", NULL, str, sizeof (str))) {
 
10040
    if (StringICmp (str, "TRUE") == 0) {
 
10041
      useIdLookup = FALSE;
9942
10042
    }
9943
10043
  }
9944
10044
 
9953
10053
    }
9954
10054
  }
9955
10055
 
 
10056
  if (GetSequinAppParam ("SETTINGS", "SUPPRESSLOCAL", NULL, str, sizeof (str))) {
 
10057
    if (StringICmp (str, "TRUE") == 0) {
 
10058
      useLocal = FALSE;
 
10059
    }
 
10060
  }
 
10061
 
9956
10062
  if (GetSequinAppParam ("SETTINGS", "GENOMETAG", NULL, str, sizeof (str))) {
9957
10063
    TrimSpacesAroundString (str);
9958
10064
    if (! StringHasNoText (str)) {
10140
10246
#endif
10141
10247
#ifdef OS_MSWIN
10142
10248
  sprintf (cmmd, "%s %s -o %s", dirsubfetchcmd, accn, path);
10143
 
  system (cmmd);
 
10249
  RunSilent (cmmd);
10144
10250
#endif
10145
10251
 
10146
10252
  fp = FileOpen (path, "r");
10197
10303
#endif
10198
10304
#ifdef OS_MSWIN
10199
10305
  sprintf (cmmd, "%s %s -o %s", dirsubfetchcmd, tsip->accession, path);
10200
 
  system (cmmd);
 
10306
  RunSilent (cmmd);
10201
10307
#endif
10202
10308
 
10203
10309
  fp = FileOpen (path, "r");
10265
10371
#endif
10266
10372
#ifdef OS_MSWIN
10267
10373
  sprintf (cmmd, "%s %s -o %s", smartfetchcmd, accn, path);
10268
 
  system (cmmd);
 
10374
  RunSilent (cmmd);
10269
10375
#endif
10270
10376
 
10271
10377
  fp = FileOpen (path, "r");
10323
10429
#endif
10324
10430
#ifdef OS_MSWIN
10325
10431
  sprintf (cmmd, "%s %s -o %s", smartfetchcmd, tsip->accession, path);
10326
 
  system (cmmd);
 
10432
  RunSilent (cmmd);
10327
10433
#endif
10328
10434
 
10329
10435
  fp = FileOpen (path, "r");
10358
10464
  return TRUE;
10359
10465
}
10360
10466
 
 
10467
static CharPtr hupfetchproc = "HUPBioseqFetch";
 
10468
 
 
10469
static CharPtr hupfetchcmd = NULL;
 
10470
 
 
10471
extern Pointer ReadFromHUP (CharPtr accn, Uint2Ptr datatype, Uint2Ptr entityID);
 
10472
extern Pointer ReadFromHUP (CharPtr accn, Uint2Ptr datatype, Uint2Ptr entityID)
 
10473
 
 
10474
{
 
10475
  Char     cmmd [256];
 
10476
  Pointer  dataptr;
 
10477
  FILE*    fp;
 
10478
  Char     path [PATH_MAX];
 
10479
 
 
10480
  if (datatype != NULL) {
 
10481
    *datatype = 0;
 
10482
  }
 
10483
  if (entityID != NULL) {
 
10484
    *entityID = 0;
 
10485
  }
 
10486
  if (! dirsubMode) return NULL;
 
10487
  if (StringHasNoText (accn)) return NULL;
 
10488
 
 
10489
  if (hupfetchcmd == NULL) {
 
10490
    if (GetAppParam ("SEQUIN", "HUP", "FETCHSCRIPT", NULL, cmmd, sizeof (cmmd))) {
 
10491
        hupfetchcmd = StringSaveNoNull (cmmd);
 
10492
    }
 
10493
  }
 
10494
  if (hupfetchcmd == NULL) return NULL;
 
10495
 
 
10496
  TmpNam (path);
 
10497
 
 
10498
#ifdef OS_UNIX
 
10499
  sprintf (cmmd, "csh %s %s > %s", hupfetchcmd, accn, path);
 
10500
  system (cmmd);
 
10501
#endif
 
10502
#ifdef OS_MSWIN
 
10503
  sprintf (cmmd, "%s %s -o %s", hupfetchcmd, accn, path);
 
10504
  RunSilent (cmmd);
 
10505
#endif
 
10506
 
 
10507
  fp = FileOpen (path, "r");
 
10508
  if (fp == NULL) {
 
10509
    FileRemove (path);
 
10510
    return NULL;
 
10511
  }
 
10512
  dataptr = ReadAsnFastaOrFlatFile (fp, datatype, entityID, FALSE, FALSE, TRUE, FALSE);
 
10513
  FileClose (fp);
 
10514
  FileRemove (path);
 
10515
  return dataptr;
 
10516
}
 
10517
 
 
10518
 
 
10519
static Int2 LIBCALLBACK HUPBioseqFetchFunc (Pointer data)
 
10520
 
 
10521
{
 
10522
  BioseqPtr         bsp;
 
10523
  Char              cmmd [256];
 
10524
  Pointer           dataptr;
 
10525
  Uint2             datatype;
 
10526
  Uint2             entityID;
 
10527
  FILE*             fp;
 
10528
  OMProcControlPtr  ompcp;
 
10529
  ObjMgrProcPtr     ompp;
 
10530
  Char              path [PATH_MAX];
 
10531
  SeqEntryPtr       sep = NULL;
 
10532
  SeqIdPtr          sip;
 
10533
  TextSeqIdPtr      tsip;
 
10534
  OMUserDataPtr     omudp;
 
10535
 
 
10536
  ompcp = (OMProcControlPtr) data;
 
10537
  if (ompcp == NULL) return OM_MSG_RET_ERROR;
 
10538
  ompp = ompcp->proc;
 
10539
  if (ompp == NULL) return OM_MSG_RET_ERROR;
 
10540
  sip = (SeqIdPtr) ompcp->input_data;
 
10541
  if (sip == NULL) return OM_MSG_RET_ERROR;
 
10542
 
 
10543
  if (sip->choice != SEQID_GENBANK) return OM_MSG_RET_ERROR;
 
10544
  tsip = (TextSeqIdPtr) sip->data.ptrvalue;
 
10545
  if (tsip == NULL || StringHasNoText (tsip->accession)) return OM_MSG_RET_ERROR;
 
10546
 
 
10547
  if (hupfetchcmd == NULL) {
 
10548
    if (GetAppParam ("SEQUIN", "HUP", "FETCHSCRIPT", NULL, cmmd, sizeof (cmmd))) {
 
10549
        hupfetchcmd = StringSaveNoNull (cmmd);
 
10550
    }
 
10551
  }
 
10552
  if (hupfetchcmd == NULL) return OM_MSG_RET_ERROR;
 
10553
 
 
10554
  TmpNam (path);
 
10555
 
 
10556
#ifdef OS_UNIX
 
10557
  sprintf (cmmd, "csh %s %s > %s", hupfetchcmd, tsip->accession, path);
 
10558
  system (cmmd);
 
10559
#endif
 
10560
#ifdef OS_MSWIN
 
10561
  sprintf (cmmd, "%s %s -o %s", hupfetchcmd, tsip->accession, path);
 
10562
  RunSilent (cmmd);
 
10563
#endif
 
10564
 
 
10565
  fp = FileOpen (path, "r");
 
10566
  if (fp == NULL) {
 
10567
    FileRemove (path);
 
10568
    return OM_MSG_RET_ERROR;
 
10569
  }
 
10570
  dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, &entityID, FALSE, FALSE, TRUE, FALSE);
 
10571
  FileClose (fp);
 
10572
  FileRemove (path);
 
10573
 
 
10574
  if (dataptr == NULL) return OM_MSG_RET_OK;
 
10575
 
 
10576
  sep = GetTopSeqEntryForEntityID (entityID);
 
10577
  if (sep == NULL) return OM_MSG_RET_ERROR;
 
10578
  bsp = BioseqFindInSeqEntry (sip, sep);
 
10579
  ompcp->output_data = (Pointer) bsp;
 
10580
  ompcp->output_entityID = ObjMgrGetEntityIDForChoice (sep);
 
10581
 
 
10582
  omudp = ObjMgrAddUserData(ompcp->output_entityID, ompp->procid, OMPROC_FETCH, 0);
 
10583
  
 
10584
 
 
10585
  return OM_MSG_RET_DONE;
 
10586
}
 
10587
 
 
10588
static Boolean HUPFetchEnable (void)
 
10589
 
 
10590
{
 
10591
  ObjMgrProcLoad (OMPROC_FETCH, hupfetchproc, hupfetchproc,
 
10592
                  OBJ_SEQID, 0, OBJ_BIOSEQ, 0, NULL,
 
10593
                  HUPBioseqFetchFunc, PROC_PRIORITY_DEFAULT);
 
10594
  return TRUE;
 
10595
}
 
10596
 
10361
10597
static CharPtr tpasmartfetchproc = "TPASmartBioseqFetch";
10362
10598
 
10363
10599
static CharPtr tpasmartfetchcmd = NULL;
10395
10631
#endif
10396
10632
#ifdef OS_MSWIN
10397
10633
  sprintf (cmmd, "%s %s -o %s", tpasmartfetchcmd, accn, path);
10398
 
  system (cmmd);
 
10634
  RunSilent (cmmd);
10399
10635
#endif
10400
10636
 
10401
10637
  fp = FileOpen (path, "r");
10452
10688
#endif
10453
10689
#ifdef OS_MSWIN
10454
10690
  sprintf (cmmd, "%s %s -o %s", tpasmartfetchcmd, tsip->accession, path);
10455
 
  system (cmmd);
 
10691
  RunSilent (cmmd);
10456
10692
#endif
10457
10693
 
10458
10694
  fp = FileOpen (path, "r");
10547
10783
  (*count)++;
10548
10784
}
10549
10785
 
10550
 
static Int4 SMReadBioseqObj(VoidPtr data, CharPtr buffer, Int4 length, Int4 fd)
 
10786
static Int4 SMReadBioseqObj(VoidPtr data, CharPtr buffer, Int4 length, void* fd)
10551
10787
{
10552
10788
    AsnIoMemPtr    aimp;
10553
10789
    BaseFormPtr    bfp;
10668
10904
    }
10669
10905
    
10670
10906
    sm_user_data = MemNew(sizeof(SMUserData));
10671
 
    sm_user_data->fd = fd;
 
10907
    sm_user_data->fd = (void*) fd;
10672
10908
    sm_user_data->header = header;
10673
10909
 
10674
10910
    if(bio_data == NULL) {
11038
11274
  subtoolEntityID = 0;
11039
11275
  leaveAsOldAsn = FALSE;
11040
11276
 
11041
 
  useSeqFetch = useEntrez;
11042
 
 
11043
11277
#if defined(OS_UNIX) || defined(WIN_MOTIF)
11044
11278
  {{
11045
11279
    Nlm_Int4         argc = GetArgc();
11090
11324
          backupMode = TRUE;
11091
11325
        } else if (StringCmp (argv[i], "-noseqfetch") == 0) {
11092
11326
          useSeqFetch = FALSE;
 
11327
        } else if (StringCmp (argv[i], "-nolocalfetch") == 0) {
 
11328
          useLocal = FALSE;
 
11329
        } else if (StringCmp (argv[i], "-noseqidlookup") == 0) {
 
11330
          useIdLookup = FALSE;
11093
11331
        }
11094
11332
#ifdef USE_SMARTNET
11095
11333
        else if (StringCmp (argv[i], "-ds") == 0) {
11127
11365
          nohelpMode = TRUE;
11128
11366
        else if (StringCmp (argv[i], "-noseqfetch") == 0)
11129
11367
          useSeqFetch = FALSE;
 
11368
        else if (StringCmp (argv[i], "-nolocalfetch") == 0)
 
11369
          useLocal = FALSE;
 
11370
        else if (StringCmp (argv[i], "-noseqidlookup") == 0)
 
11371
          useIdLookup = FALSE;
11130
11372
#ifdef USE_SMARTNET
11131
11373
        else if (StringNCmp (argv[i], "-z", 2) == 0) {
11132
11374
          smartnetMode = TRUE;
11253
11495
  VSeqMgrInit (FALSE);
11254
11496
  WatchCursor ();
11255
11497
 
11256
 
#ifdef USE_SMARTNET
11257
 
  if (dirsubMode) {
11258
 
    DirSubFetchEnable ();
11259
 
    SmartFetchEnable ();
11260
 
    TPASmartFetchEnable ();
11261
 
  }
11262
 
#endif
 
11498
  /* register fetch functions */
11263
11499
 
11264
 
/*#ifdef USE_ENTREZ*/
11265
11500
  if (useEntrez) {
11266
11501
    /* EntrezBioseqFetchEnable ("Sequin", FALSE); */
11267
11502
    if (useSeqFetch) {
11268
11503
      /* ID1BioseqFetchEnable ("Sequin", FALSE); */
11269
11504
      PubSeqFetchEnable ();
11270
11505
      PubMedFetchEnable ();
11271
 
    } else {
 
11506
    } else if (useIdLookup) {
11272
11507
      PubSeqFetchEnableEx (FALSE, TRUE, TRUE, TRUE, TRUE);
11273
11508
      PubMedFetchEnable ();
11274
11509
    }
11275
11510
  }
11276
 
/*#endif*/
11277
 
 
11278
 
/*#ifdef USE_LOCAL*/
 
11511
 
 
11512
#ifdef USE_SMARTNET
 
11513
  if (dirsubMode) {
 
11514
    if (useSeqFetch) {
 
11515
      /* DirSubFetchEnable (); */
 
11516
      TPASmartFetchEnable ();
 
11517
      SmartFetchEnable ();
 
11518
      HUPFetchEnable ();
 
11519
    }
 
11520
  }
 
11521
#endif
 
11522
 
11279
11523
  if (useLocal) {
11280
11524
    LocalSeqFetchInit (FALSE);
11281
11525
  }
11282
 
/*#endif*/
 
11526
 
 
11527
/*
 
11528
#ifdef USE_SMARTNET
 
11529
  if (dirsubMode) {
 
11530
    if (only_use_smart) {
 
11531
      SmartFetchEnable ();
 
11532
    } else {
 
11533
      DirSubFetchEnable ();
 
11534
      SmartFetchEnable ();
 
11535
      TPASmartFetchEnable ();
 
11536
    }
 
11537
  }
 
11538
#endif
 
11539
 
 
11540
  if (! only_use_smart) {
 
11541
    if (useEntrez) {
 
11542
      if (useSeqFetch) {
 
11543
        PubSeqFetchEnable ();
 
11544
        PubMedFetchEnable ();
 
11545
      } else {
 
11546
        PubSeqFetchEnableEx (FALSE, TRUE, TRUE, TRUE, TRUE);
 
11547
        PubMedFetchEnable ();
 
11548
      }
 
11549
    }
 
11550
 
 
11551
    if (useLocal) {
 
11552
      LocalSeqFetchInit (FALSE);
 
11553
    }
 
11554
  }
 
11555
*/
11283
11556
 
11284
11557
#ifdef WIN_MAC
11285
11558
  SetDeactivate (NULL, MacDeactProc);
11639
11912
  Remove (initSubmitForm);
11640
11913
  Remove (formatForm);
11641
11914
  Remove (helpForm);
 
11915
 
 
11916
  FreeSqnTempFiles ();
 
11917
 
11642
11918
  ArrowCursor ();
11643
11919
  Update ();
11644
11920
 
11732
12008
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
11733
12009
  if (sep == NULL) return;
11734
12010
 
11735
 
  bad_biop_list = Taxon3CheckSpecificHostInSeqEntry (sep, TRUE);
 
12011
  bad_biop_list = Taxon3CheckSpecificHostInSeqEntry (sep, TRUE, FALSE);
11736
12012
 
11737
12013
  if (bad_biop_list == NULL)
11738
12014
  {
11747
12023
  CloseLog (lip);
11748
12024
  lip = FreeLog (lip);
11749
12025
}
 
12026
 
 
12027
 
 
12028
typedef struct updatefeaturesform {
 
12029
  FORM_MESSAGE_BLOCK
 
12030
  DialoG new_features;
 
12031
  ValNodePtr feat_list;
 
12032
  SeqAnnotPtr sap;
 
12033
} UpdateFeaturesFormData, PNTR UpdateFeaturesFormPtr;
 
12034
 
 
12035
 
 
12036
static void CleanupUpdateFeaturesForm (GraphiC g, VoidPtr data)
 
12037
{
 
12038
    UpdateFeaturesFormPtr f;
 
12039
 
 
12040
    f = (UpdateFeaturesFormPtr) data;
 
12041
    if (f != NULL) {
 
12042
      f->feat_list = FreeClickableList (f->feat_list);
 
12043
      f->sap = SeqAnnotFree (f->sap);
 
12044
    }
 
12045
    StdCleanupFormProc (g, data);
 
12046
}
 
12047
 
 
12048
 
 
12049
 
 
12050
static CharPtr GetNewItemDescription (SeqFeatPtr sfp)
 
12051
{
 
12052
  CharPtr location, label, row_text;
 
12053
  Char buf[129];
 
12054
  
 
12055
  location = SeqLocPrintUseBestID (sfp->location);
 
12056
  label = (CharPtr) FeatDefTypeLabel(sfp);
 
12057
 
 
12058
  FeatDefLabel (sfp, buf, sizeof (buf) - 1, OM_LABEL_CONTENT);
 
12059
 
 
12060
  row_text = (CharPtr) MemNew (sizeof (Char) * 
 
12061
                              (StringLen (label) 
 
12062
                              + StringLen (buf) 
 
12063
                              + StringLen (location) 
 
12064
                              + 6));
 
12065
  sprintf (row_text, "%s:%s:%s\n", label, buf, location);
 
12066
  location = MemFree (location);
 
12067
  return row_text;
 
12068
}
 
12069
 
 
12070
 
 
12071
static ClickableItemPtr PutFeaturesInOldItem (ValNodePtr item_list)
 
12072
{
 
12073
  ClickableItemPtr cip_olditems, cip;
 
12074
  ValNodePtr       vnp;
 
12075
 
 
12076
  cip_olditems = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
12077
  if (item_list == NULL) {
 
12078
    cip_olditems->description = StringSave ("No old features found");
 
12079
    cip_olditems->chosen = FALSE;
 
12080
  } else {
 
12081
    for (vnp = item_list; vnp != NULL; vnp = vnp->next) {
 
12082
      cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
12083
      cip->description = GetNewItemDescription (vnp->data.ptrvalue);
 
12084
      cip->chosen = TRUE;
 
12085
      ValNodeAddPointer (&(cip->item_list), OBJ_SEQFEAT, vnp->data.ptrvalue);
 
12086
      ValNodeAddPointer (&(cip_olditems->subcategories), 0, cip);
 
12087
    }
 
12088
    cip_olditems->description = StringSave ("Old Features (check to delete)");
 
12089
    cip_olditems->chosen = TRUE;
 
12090
  }
 
12091
  return cip_olditems;
 
12092
}
 
12093
 
 
12094
 
 
12095
static void MarkChosenFeatures (ValNodePtr item_list, Boolean delete_marked)
 
12096
{
 
12097
  ClickableItemPtr cip;
 
12098
  ValNodePtr vnp;
 
12099
  SeqFeatPtr sfp;
 
12100
 
 
12101
  while (item_list != NULL) {
 
12102
    cip = (ClickableItemPtr) item_list->data.ptrvalue;
 
12103
    if (cip != NULL) {
 
12104
      for (vnp = cip->item_list; vnp != NULL; vnp = vnp->next) {
 
12105
        if (vnp->choice == OBJ_SEQFEAT) {
 
12106
          sfp = (SeqFeatPtr) vnp->data.ptrvalue;
 
12107
          if ((cip->chosen && delete_marked) || (!cip->chosen && !delete_marked)) {
 
12108
            sfp->idx.deleteme = TRUE;
 
12109
          }
 
12110
        }
 
12111
      }
 
12112
    }
 
12113
    item_list = item_list->next;
 
12114
  }
 
12115
}
 
12116
 
 
12117
 
 
12118
static void MarkChosenFeaturesForBioseqs (ValNodePtr feat_list)
 
12119
{
 
12120
  ClickableItemPtr cip, cip_new, cip_old;
 
12121
 
 
12122
  if (feat_list == NULL) return;
 
12123
  cip = (ClickableItemPtr) feat_list->data.ptrvalue;
 
12124
  if (cip->item_list != NULL && cip->item_list->choice == OBJ_BIOSEQ) {
 
12125
    if (cip->subcategories != NULL) {
 
12126
      cip_new = (ClickableItemPtr) cip->subcategories->data.ptrvalue;
 
12127
      MarkChosenFeatures (cip_new->subcategories, FALSE);
 
12128
      if (cip->subcategories->next != NULL) {
 
12129
        cip_old = (ClickableItemPtr) cip->subcategories->next->data.ptrvalue;
 
12130
        MarkChosenFeatures (cip_old->subcategories, TRUE);
 
12131
      }
 
12132
    }
 
12133
    MarkChosenFeaturesForBioseqs (feat_list->next);
 
12134
  } else if (feat_list->next != NULL && feat_list->next->next == NULL && cip->item_list == NULL) {
 
12135
    cip_new = (ClickableItemPtr) feat_list->data.ptrvalue;
 
12136
    cip_old = (ClickableItemPtr) feat_list->next->data.ptrvalue;
 
12137
    MarkChosenFeatures (cip_new->subcategories, FALSE);
 
12138
    MarkChosenFeatures (cip_old->subcategories, TRUE);
 
12139
  }
 
12140
}
 
12141
 
 
12142
 
 
12143
static void DoUpdateFeatures (ButtoN b)
 
12144
{
 
12145
  UpdateFeaturesFormPtr f;
 
12146
 
 
12147
  f = (UpdateFeaturesFormPtr) GetObjectExtra (b);
 
12148
  if (f == NULL) return;
 
12149
 
 
12150
  MarkChosenFeaturesForBioseqs (f->feat_list);
 
12151
  
 
12152
  SmartAttachSeqAnnotToSeqEntry (f->input_entityID, f->sap, NULL);
 
12153
  f->sap = NULL;
 
12154
 
 
12155
  DeleteMarkedObjects (f->input_entityID, 0, NULL);
 
12156
  ObjMgrSetDirtyFlag (f->input_entityID, TRUE);
 
12157
  ObjMgrSendMsg (OM_MSG_UPDATE, f->input_entityID, 0, 0);
 
12158
 
 
12159
  Remove (f->form);
 
12160
}
 
12161
 
 
12162
 
 
12163
extern void UpdateFeatures (IteM i)
 
12164
{
 
12165
  BaseFormPtr  bfp;
 
12166
  SeqEntryPtr  sep;
 
12167
  Pointer        dataptr;
 
12168
  Uint2          datatype;
 
12169
  FILE           *fp;
 
12170
  Char           path [PATH_MAX];
 
12171
  SeqAnnotPtr    sap;
 
12172
  SeqFeatPtr     sfp;
 
12173
  ValNodePtr     new_feat_list = NULL, no_bsp_list = NULL, old_item_list;
 
12174
  Int4           leftmost = -1, rightmost = -1, new_left, new_right, tmp;
 
12175
  BioseqPtr      bsp, last_bsp = NULL;
 
12176
  ClickableItemPtr cip = NULL, cip_newitems = NULL, cip_olditems, cip_newfeat;
 
12177
  SeqLocPtr        slp;
 
12178
  WindoW           w;
 
12179
  GrouP            h, g, c;
 
12180
  ButtoN           b;
 
12181
  UpdateFeaturesFormPtr f;
 
12182
  Char             id [42];
 
12183
 
 
12184
#ifdef WIN_MAC
 
12185
  bfp = currentFormDataPtr;
 
12186
#else
 
12187
  bfp = GetObjectExtra (i);
 
12188
#endif
 
12189
  if (bfp == NULL) return;
 
12190
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
12191
  if (sep == NULL) return;
 
12192
 
 
12193
  path [0] = '\0';
 
12194
  if (!GetInputFileName (path, sizeof (path), "", "TEXT")) {
 
12195
    return;
 
12196
  }
 
12197
 
 
12198
  fp = FileOpen (path, "r");
 
12199
  if (fp == NULL) {
 
12200
    Message (MSG_ERROR, "Unable to open file!");
 
12201
    return;
 
12202
  }
 
12203
  dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, FALSE, FALSE,
 
12204
                                    TRUE, TRUE);
 
12205
  FileClose (fp);
 
12206
  if (dataptr == NULL || datatype != OBJ_SEQANNOT) {
 
12207
    Message (MSG_ERROR, "File does not contain feature table!");
 
12208
    return;
 
12209
  }
 
12210
 
 
12211
  sap = (SeqAnnotPtr) dataptr;
 
12212
  if (sap->type != 1) {
 
12213
    Message (MSG_ERROR, "File does not contain feature table!");
 
12214
    sap = SeqAnnotFree (sap);
 
12215
    return;
 
12216
  }
 
12217
 
 
12218
  // list features for each bioseq
 
12219
  for (sfp = sap->data; sfp != NULL; sfp = sfp->next) {
 
12220
    bsp = BioseqFindFromSeqLoc (sfp->location);
 
12221
    if (bsp == NULL) {    
 
12222
      ValNodeAddPointer (&no_bsp_list, OBJ_SEQFEAT, sfp);
 
12223
    } else {
 
12224
      if (bsp != last_bsp) {   
 
12225
        if (last_bsp != NULL) {
 
12226
          slp = SeqLocIntNew (leftmost, rightmost, Seq_strand_plus, SeqIdDup (SeqIdFindWorst (bsp->id)));
 
12227
          old_item_list = ListFeaturesOverlappingLocation (last_bsp, slp, 0, 0);
 
12228
          slp = SeqLocFree (slp);
 
12229
          cip_olditems = PutFeaturesInOldItem (old_item_list);
 
12230
          old_item_list = ValNodeFree (old_item_list);
 
12231
          ValNodeAddPointer (&(cip->subcategories), 0, cip_olditems);
 
12232
        }   
 
12233
        cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
12234
        ValNodeAddPointer (&(cip->item_list), OBJ_BIOSEQ, bsp);
 
12235
 
 
12236
        SeqIdWrite (SeqIdFindBest (bsp->id, SEQID_GENBANK), id, PRINTID_FASTA_LONG, sizeof (id) - 1);
 
12237
        cip->description = StringSave (id);
 
12238
        cip_newitems = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
12239
        cip_newitems->description = StringSave ("New Features (check to import)");
 
12240
        cip_newitems->chosen = TRUE;
 
12241
        ValNodeAddPointer (&(cip->subcategories), 0, cip_newitems);
 
12242
        last_bsp = bsp;
 
12243
        ValNodeAddPointer (&new_feat_list, 0, cip);
 
12244
        leftmost = -1;
 
12245
        rightmost = -1;
 
12246
      }
 
12247
      cip_newfeat = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
12248
      cip_newfeat->description = GetNewItemDescription (sfp);      
 
12249
      cip_newfeat->chosen = TRUE;
 
12250
      ValNodeAddPointer (&(cip_newfeat->item_list), OBJ_SEQFEAT, sfp);
 
12251
      ValNodeAddPointer (&(cip_newitems->subcategories), 0, cip_newfeat);
 
12252
      new_left = SeqLocStart (sfp->location);
 
12253
      new_right = SeqLocStop (sfp->location);
 
12254
      if (new_left > new_right) {
 
12255
        tmp = new_left;
 
12256
        new_left = new_right;
 
12257
        new_right = tmp;
 
12258
      }
 
12259
      if (leftmost == -1 || new_left < leftmost) {
 
12260
        leftmost = new_left;
 
12261
      }
 
12262
      if (rightmost == -1 || new_right > rightmost) {
 
12263
        rightmost = new_right;
 
12264
      }
 
12265
    }
 
12266
  }
 
12267
  if (last_bsp != NULL) {
 
12268
    slp = SeqLocIntNew (leftmost, rightmost, Seq_strand_plus, SeqIdDup (SeqIdFindWorst (bsp->id)));
 
12269
    old_item_list = ListFeaturesOverlappingLocation (last_bsp, slp, 0, 0);
 
12270
    slp = SeqLocFree (slp);
 
12271
    cip_olditems = PutFeaturesInOldItem (old_item_list);
 
12272
    old_item_list = ValNodeFree (old_item_list);
 
12273
    ValNodeAddPointer (&(cip->subcategories), 0, cip_olditems);
 
12274
  }
 
12275
 
 
12276
  if (no_bsp_list != NULL) {
 
12277
    Message (MSG_ERROR, "%d features in table are not found on a Bioseq in this record!", ValNodeLen (no_bsp_list));
 
12278
    no_bsp_list = ValNodeFree (no_bsp_list);
 
12279
  }
 
12280
 
 
12281
  if (new_feat_list == NULL) {
 
12282
    Message (MSG_ERROR, "No features found!");
 
12283
    sap = SeqAnnotFree (sap);
 
12284
    return;
 
12285
  }
 
12286
  if (new_feat_list->next == NULL) {
 
12287
    no_bsp_list = new_feat_list;
 
12288
    cip = (ClickableItemPtr) new_feat_list->data.ptrvalue;
 
12289
    new_feat_list = cip->subcategories;
 
12290
    cip->subcategories = NULL;
 
12291
    no_bsp_list = FreeClickableList (no_bsp_list);
 
12292
  }  
 
12293
   
 
12294
 
 
12295
  /* Now create dialog to allow user to select new features to import and existing features to delete */
 
12296
  f = (UpdateFeaturesFormPtr) MemNew (sizeof (UpdateFeaturesFormData));
 
12297
  w = FixedWindow (-50, -33, -10, -10, "Update Features", StdCloseWindowProc);
 
12298
  SetObjectExtra (w, f, CleanupUpdateFeaturesForm);
 
12299
  f->form = (ForM) w;
 
12300
  f->input_entityID = bfp->input_entityID;
 
12301
  f->feat_list = new_feat_list;
 
12302
  f->sap = sap;
 
12303
  h = HiddenGroup (w, -1, 0, NULL);
 
12304
  SetGroupSpacing (h, 10, 10);
 
12305
  g = HiddenGroup (h, 2, 0, NULL);
 
12306
  f->new_features = CreateClickableListDialog (g, "New Features (check to import)", "label1", NULL, NULL, NULL, GetDiscrepancyItemText);
 
12307
  PointerToDialog (f->new_features, new_feat_list);
 
12308
/*  f->old_features = CreateClickableListDialog (g, "Old Features", "label1",
 
12309
                                               ScrollToDiscrepancyItem, EditDiscrepancyItem, bfp,
 
12310
                                               GetDiscrepancyItemText); */
 
12311
  c = HiddenGroup (h, 4, 0, NULL);
 
12312
  b = PushButton (c, "Accept", DoUpdateFeatures);
 
12313
  SetObjectExtra (b, f, NULL);
 
12314
  PushButton (c, "Cancel", StdCancelButtonProc);
 
12315
  
 
12316
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
 
12317
  Show (w);
 
12318
  Select (w);
 
12319
 
 
12320
 
 
12321
}
 
12322