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

« back to all changes in this revision

Viewing changes to demo/cleanasn.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:   10/19/99
31
31
*
32
 
* $Revision: 6.29 $
 
32
* $Revision: 6.37 $
33
33
*
34
34
* File Description: 
35
35
*
60
60
#ifdef INTERNAL_NCBI_CLEANASN
61
61
#include <accpubseq.h>
62
62
#endif
 
63
#define NLM_GENERATED_CODE_PROTO
 
64
#include <objmacro.h>
 
65
#include <macroapi.h>
63
66
 
64
 
#define CLEANASN_APP_VER "2.2"
 
67
#define CLEANASN_APP_VER "2.8"
65
68
 
66
69
CharPtr CLEANASN_APPLICATION = CLEANASN_APP_VER;
67
70
 
68
71
typedef struct cleanflags {
69
72
  Char          buf [64];
 
73
  Int4          gi;
70
74
  Boolean       batch;
71
75
  Boolean       binary;
72
76
  Boolean       compressed;
82
86
  CharPtr       feat;
83
87
  CharPtr       desc;
84
88
  CharPtr       mods;
 
89
  ValNodePtr    action_list;
85
90
  Boolean       taxon;
86
91
  Boolean       pub;
87
92
  Int4          okay;
891
896
  MemFree (str4);
892
897
}
893
898
 
894
 
static void DoCleanup (
 
899
static ByteStorePtr Se2Bs (
 
900
  SeqEntryPtr sep
 
901
)
 
902
 
 
903
{
 
904
  AsnIoBSPtr    aibp;
 
905
  ByteStorePtr  bs;
 
906
 
 
907
  if (sep == NULL) return NULL;
 
908
 
 
909
  bs = BSNew (1000);
 
910
  if (bs == NULL) return NULL;
 
911
  aibp = AsnIoBSOpen ("w", bs);
 
912
  if (aibp == NULL) return NULL;
 
913
 
 
914
  SeqEntryAsnWrite (sep, aibp->aip, NULL);
 
915
 
 
916
  AsnIoFlush (aibp->aip);
 
917
  AsnIoBSClose (aibp);
 
918
 
 
919
  return bs;
 
920
}
 
921
 
 
922
static void RemoveFeatureCitations (
 
923
  SeqFeatPtr sfp,
 
924
  Pointer userdata
 
925
)
 
926
 
 
927
{
 
928
  if (sfp == NULL || sfp->cit == NULL) return;
 
929
 
 
930
  sfp->cit = PubSetFree (sfp->cit);
 
931
}
 
932
 
 
933
#ifdef OS_UNIX
 
934
static SeqEntryPtr CppBasicCleanup (
 
935
  SeqEntryPtr sep,
 
936
  CleanFlagPtr cfp
 
937
)
 
938
 
 
939
{
 
940
  AsnIoPtr      aip, aop;
 
941
  ByteStorePtr  bs1, bs2;
 
942
  Char          cmmd [256];
 
943
  SeqEntryPtr   csep, nsep;
 
944
  Char          path1 [PATH_MAX];
 
945
  Char          path2 [PATH_MAX];
 
946
  Char          path3 [PATH_MAX];
 
947
 
 
948
  if (sep == NULL || cfp == NULL) return NULL;
 
949
 
 
950
  VisitFeaturesInSep (sep, NULL, RemoveFeatureCitations);
 
951
 
 
952
  TmpNam (path1);
 
953
  TmpNam (path2);
 
954
  TmpNam (path3);
 
955
 
 
956
  aop = AsnIoOpen (path1, "w");
 
957
  SeqEntryAsnWrite (sep, aop, NULL);
 
958
  AsnIoClose (aop);
 
959
 
 
960
  sprintf (cmmd, "%s -i %s | cleanasn -a e -o %s",
 
961
           "~/ncbi_cxx/compilers/xCode/build/bin/Debug/test_basic_cleanup",
 
962
           path1, path2);
 
963
  system (cmmd);
 
964
 
 
965
  sprintf (cmmd, "cleanasn -i %s -o %s -K b",
 
966
           path1, path3);
 
967
  system (cmmd);
 
968
 
 
969
  aip = AsnIoOpen (path3, "r");
 
970
  csep = SeqEntryAsnRead (aip, NULL);
 
971
  AsnIoClose (aip);
 
972
 
 
973
  bs1 = Se2Bs (csep);
 
974
 
 
975
  aip = AsnIoOpen (path2, "r");
 
976
  nsep = SeqEntryAsnRead (aip, NULL);
 
977
  AsnIoClose (aip);
 
978
 
 
979
  bs2 = Se2Bs (nsep);
 
980
 
 
981
  if (nsep == NULL) {
 
982
    if (cfp->logfp != NULL) {
 
983
      fprintf (cfp->logfp, "EMPTY %s\n", cfp->buf);
 
984
      fflush (cfp->logfp);
 
985
    }
 
986
  } else if (! BSEqual (bs1, bs2)) {
 
987
    if (cfp->logfp != NULL) {
 
988
      fprintf (cfp->logfp, "BSEC DIFF %s\n", cfp->buf);
 
989
      fflush (cfp->logfp);
 
990
    }
 
991
    if (cfp->gi > 0) {
 
992
      sprintf (cmmd, "echo '' >> ~/Desktop/diffclean.txt");
 
993
      system (cmmd);
 
994
      sprintf (cmmd, "echo '' >> ~/Desktop/diffclean.txt");
 
995
      system (cmmd);
 
996
      sprintf (cmmd, "echo '********** gi|%ld **********' >> ~/Desktop/diffclean.txt", (long) cfp->gi);
 
997
      system (cmmd);
 
998
      sprintf (cmmd, "echo '' >> ~/Desktop/diffclean.txt");
 
999
      system (cmmd);
 
1000
      sprintf (cmmd, "diff %s %s >> ~/Desktop/diffclean.txt", path3, path2);
 
1001
      system (cmmd);
 
1002
    }
 
1003
  }
 
1004
 
 
1005
  BSFree (bs1);
 
1006
  BSFree (bs2);
 
1007
 
 
1008
  SeqEntryFree (csep);
 
1009
 
 
1010
  sprintf (cmmd, "rm %s; rm %s; rm %s", path1, path2, path3);
 
1011
  system (cmmd);
 
1012
 
 
1013
  return nsep;
 
1014
}
 
1015
#endif
 
1016
 
 
1017
static time_t DoCleanup (
895
1018
  SeqEntryPtr sep,
896
1019
  Uint2 entityID,
897
 
  CleanFlagPtr cfp
 
1020
  CleanFlagPtr cfp,
 
1021
  AsnIoPtr aop,
 
1022
  AsnTypePtr atp,
 
1023
  SeqSubmitPtr ssp
898
1024
)
899
1025
 
900
1026
{
901
1027
  BioseqPtr    bsp;
902
 
  SeqEntryPtr  fsep;
 
1028
  SeqEntryPtr  fsep, nsep = NULL;
903
1029
  SeqIdPtr     sip, siphead;
904
 
 
905
 
  if (sep == NULL || cfp == NULL) return;
 
1030
  time_t       starttime, stoptime;
 
1031
 
 
1032
  if (sep == NULL || cfp == NULL) return 0;
 
1033
 
 
1034
  starttime = GetSecs ();
906
1035
 
907
1036
  StringCpy (cfp->buf, "");
 
1037
  cfp->gi = 0;
908
1038
  fsep = FindNthBioseq (sep, 1);
909
1039
  if (fsep != NULL && fsep->choice == 1) {
910
1040
    bsp = (BioseqPtr) fsep->data.ptrvalue;
912
1042
      siphead = SeqIdSetDup (bsp->id);
913
1043
      for (sip = siphead; sip != NULL; sip = sip->next) {
914
1044
        SeqIdStripLocus (sip);
 
1045
        if (sip->choice == SEQID_GI) {
 
1046
          cfp->gi = (Int4) sip->data.intvalue;
 
1047
        }
915
1048
      }
916
1049
      SeqIdWrite (siphead, cfp->buf, PRINTID_FASTA_LONG, sizeof (cfp->buf));
917
1050
      SeqIdSetFree (siphead);
920
1053
 
921
1054
  if (StringChr (cfp->report, 'r') != NULL) {
922
1055
    DoASNReport (sep, cfp);
923
 
    return;
 
1056
    stoptime = GetSecs ();
 
1057
    return stoptime - starttime;
924
1058
  }
925
1059
  if (StringChr (cfp->report, 'g') != NULL) {
926
1060
    DoGBFFReport (sep, cfp);
927
 
    return;
 
1061
    stoptime = GetSecs ();
 
1062
    return stoptime - starttime;
928
1063
  }
929
1064
  if (StringChr (cfp->report, 'm') != NULL) {
930
1065
    DoModernizeReport (sep, cfp);
931
 
    return;
 
1066
    stoptime = GetSecs ();
 
1067
    return stoptime - starttime;
932
1068
  }
933
1069
 
934
1070
  if (cfp->logfp != NULL) {
939
1075
  if (StringChr (cfp->clean, 'b') != NULL) {
940
1076
    BasicSeqEntryCleanup (sep);
941
1077
  }
 
1078
#ifdef OS_UNIX
 
1079
  if (StringChr (cfp->clean, 'p') != NULL) {
 
1080
    nsep = CppBasicCleanup (sep, cfp);
 
1081
  }
 
1082
#endif
942
1083
  if (StringChr (cfp->clean, 's') != NULL) {
943
1084
    SeriousSeqEntryCleanup (sep, NULL, NULL);
944
1085
  }
 
1086
  if (StringChr (cfp->clean, 'g') != NULL) {
 
1087
    GpipeSeqEntryCleanup (sep);
 
1088
  }
945
1089
  if (StringChr (cfp->clean, 'n') != NULL) {
946
1090
    NormalizeDescriptorOrder (sep);
947
1091
  }
 
1092
  if (StringChr (cfp->clean, 'u') != NULL) {
 
1093
    RemoveAllNcbiCleanupUserObjects (sep);
 
1094
  }
948
1095
 
949
1096
  if (StringChr (cfp->modernize, 'g') != NULL) {
950
1097
    VisitFeaturesInSep (sep, NULL, ModGenes);
1000
1147
    SeqMgrIndexFeatures (entityID, 0);
1001
1148
    DoAutoDef (sep, entityID);
1002
1149
  }
 
1150
 
 
1151
  if (cfp->action_list != NULL) {
 
1152
    ApplyMacroToSeqEntry (sep, cfp->action_list, NULL, NULL);
 
1153
  }
 
1154
 
 
1155
  stoptime = GetSecs ();
 
1156
 
 
1157
  if (aop != NULL) {
 
1158
        if (ssp != NULL) {
 
1159
          SeqSubmitAsnWrite (ssp, aop, atp);
 
1160
        } else if (nsep != NULL) {
 
1161
          SeqEntryAsnWrite (nsep, aop, atp);
 
1162
          SeqEntryFree (nsep);
 
1163
        } else {
 
1164
          SeqEntryAsnWrite (sep, aop, atp);
 
1165
        }
 
1166
  }
 
1167
 
 
1168
  return stoptime - starttime;
1003
1169
}
1004
1170
 
1005
1171
static void CleanupSingleRecord (
1017
1183
  Char          path [PATH_MAX];
1018
1184
  CharPtr       ptr;
1019
1185
  SeqEntryPtr   sep;
 
1186
  SeqSubmitPtr  ssp = NULL;
1020
1187
 
1021
1188
  if (cfp == NULL) return;
1022
1189
 
1042
1209
      return;
1043
1210
    }
1044
1211
 
 
1212
    SeqMgrHoldIndexing (TRUE);
1045
1213
    switch (cfp->type) {
1046
1214
      case 2 :
1047
1215
        dataptr = (Pointer) SeqEntryAsnRead (aip, NULL);
1057
1225
        break;
1058
1226
      case 5 :
1059
1227
        dataptr = (Pointer) SeqSubmitAsnRead (aip, NULL);
 
1228
        ssp = (SeqSubmitPtr) dataptr;
1060
1229
        datatype = OBJ_SEQSUB;
1061
1230
        break;
1062
1231
      default :
1063
1232
        break;
1064
1233
    }
 
1234
    SeqMgrHoldIndexing (FALSE);
1065
1235
 
1066
1236
    AsnIoClose (aip);
1067
1237
 
1122
1292
      sep = GetTopSeqEntryForEntityID (entityID);
1123
1293
      if (sep != NULL && StringDoesHaveText (path)) {
1124
1294
 
1125
 
        DoCleanup (sep, entityID, cfp);
1126
 
 
1127
1295
        aop = AsnIoOpen (path, "w");
 
1296
 
 
1297
        DoCleanup (sep, entityID, cfp, aop, NULL, ssp);
 
1298
 
1128
1299
        if (aop != NULL) {
1129
 
          if (datatype == OBJ_SEQSUB) {
1130
 
            SeqSubmitAsnWrite ((SeqSubmitPtr) dataptr, aop, NULL);
1131
 
          } else {
1132
 
            SeqEntryAsnWrite (sep, aop, NULL);
1133
 
          }
1134
1300
          AsnIoFlush (aop);
1135
1301
          AsnIoClose (aop);
1136
1302
        }
1162
1328
  Char         path [PATH_MAX];
1163
1329
  CharPtr      ptr;
1164
1330
  SeqEntryPtr  sep;
1165
 
  time_t       starttime, stoptime, worsttime;
 
1331
  time_t       timediff, worsttime;
1166
1332
#ifdef OS_UNIX
1167
1333
  Char         cmmd [256];
1168
1334
  CharPtr      gzcatprog;
1269
1435
    while ((atp = AsnReadId (aip, cfp->amp, atp)) != NULL) {
1270
1436
      if (atp == cfp->atp_se) {
1271
1437
 
 
1438
        SeqMgrHoldIndexing (TRUE);
1272
1439
        sep = SeqEntryAsnRead (aip, atp);
 
1440
        SeqMgrHoldIndexing (FALSE);
 
1441
 
1273
1442
        if (sep != NULL) {
1274
1443
 
1275
1444
          entityID = ObjMgrGetEntityIDForChoice (sep);
1276
1445
 
1277
 
          starttime = GetSecs ();
1278
 
          DoCleanup (sep, entityID, cfp);
1279
 
          stoptime = GetSecs ();
 
1446
          timediff = DoCleanup (sep, entityID, cfp, aop, cfp->atp_se, NULL);
1280
1447
 
1281
 
          if (stoptime - starttime > worsttime) {
1282
 
            worsttime = stoptime - starttime;
 
1448
          if (timediff > worsttime) {
 
1449
            worsttime = timediff;
1283
1450
            StringCpy (longest, cfp->buf);
1284
1451
          }
1285
1452
          numrecords++;
1286
1453
 
1287
 
          SeqEntryAsnWrite (sep, aop, cfp->atp_se);
1288
 
 
1289
1454
          ObjMgrFreeByEntityID (entityID);
1290
1455
        }
1291
1456
 
1370
1535
#define N_argLink         16
1371
1536
#define F_argFeat         17
1372
1537
#define D_argDesc         18
1373
 
#define M_argMods         19
1374
 
#define T_argTaxonLookup  20
1375
 
#define P_argPubLookup    21
 
1538
#define X_argMods         19
 
1539
#define M_argMacro        20
 
1540
#define T_argTaxonLookup  21
 
1541
#define P_argPubLookup    22
1376
1542
 
1377
1543
Args myargs [] = {
1378
1544
  {"Path to Files", NULL, NULL, NULL,
1418
1584
    TRUE, 'm', ARG_STRING, 0.0, 0, NULL},
1419
1585
  {"Cleanup\n"
1420
1586
   "      b BasicSeqEntryCleanup\n"
 
1587
   "      p C++ BasicCleanup\n"
1421
1588
   "      s SeriousSeqEntryCleanup\n"
1422
 
   "      n Normalize Descriptor Order", NULL, NULL, NULL,
 
1589
   "      g GpipeSeqEntryCleanup\n"
 
1590
   "      n Normalize Descriptor Order\n"
 
1591
   "      u Remove NcbiCleanup User Objects", NULL, NULL, NULL,
1423
1592
    TRUE, 'K', ARG_STRING, 0.0, 0, NULL},
1424
1593
  {"Modernize\n"
1425
1594
   "      g Gene\n"
1442
1611
    TRUE, 'D', ARG_STRING, 0.0, 0, NULL},
1443
1612
  {"Miscellaneous\n"
1444
1613
   "      d Automatic Definition Line", NULL, NULL, NULL,
1445
 
    TRUE, 'M', ARG_STRING, 0.0, 0, NULL},
 
1614
    TRUE, 'X', ARG_STRING, 0.0, 0, NULL},
 
1615
  {"Macro File", NULL, NULL, NULL,
 
1616
    TRUE, 'M', ARG_FILE_IN, 0.0, 0, NULL},
1446
1617
  {"Taxonomy Lookup", "F", NULL, NULL,
1447
1618
    TRUE, 'T', ARG_BOOLEAN, 0.0, 0, NULL},
1448
1619
  {"Publication Lookup", "F", NULL, NULL,
1452
1623
Int2 Main (void)
1453
1624
 
1454
1625
{
 
1626
  ValNodePtr     action_list;
 
1627
  AsnIoPtr       aip;
1455
1628
  Char           app [64], mode, type;
1456
1629
  CleanFlagData  cfd;
1457
 
  CharPtr        directory, filter, infile, logfile, outfile, results, str, suffix;
 
1630
  CharPtr        directory, filter, infile, logfile, outfile,
 
1631
                 macro_file, results, str, suffix;
1458
1632
  Boolean        remote;
1459
1633
  time_t         runtime, starttime, stoptime;
1460
1634
 
1583
1757
  cfd.link = myargs [N_argLink].strvalue;
1584
1758
  cfd.feat = myargs [F_argFeat].strvalue;
1585
1759
  cfd.desc = myargs [D_argDesc].strvalue;
1586
 
  cfd.mods = myargs [M_argMods].strvalue;
 
1760
  cfd.mods = myargs [X_argMods].strvalue;
1587
1761
  cfd.taxon = (Boolean) myargs [T_argTaxonLookup].intvalue;
1588
1762
  cfd.pub = (Boolean) myargs [P_argPubLookup].intvalue;
1589
1763
 
 
1764
  macro_file = myargs [M_argMacro].strvalue;
 
1765
  if (StringDoesHaveText (macro_file)) {
 
1766
    aip = AsnIoOpen (macro_file, "r");
 
1767
    if (aip == NULL) {
 
1768
      Message (MSG_FATAL, "Unable to open macro file '%s'", macro_file);
 
1769
      return 1;
 
1770
    }
 
1771
    action_list = MacroActionListAsnRead (aip, NULL);
 
1772
    AsnIoClose (aip);
 
1773
    if (action_list == NULL) {
 
1774
      Message (MSG_FATAL, "Unable to read macro file '%s'", macro_file);
 
1775
    }
 
1776
    cfd.action_list = action_list;
 
1777
  }
 
1778
 
1590
1779
  cfd.amp = AsnAllModPtr ();
1591
1780
  cfd.atp_bss = AsnFind ("Bioseq-set");
1592
1781
  cfd.atp_bsss = AsnFind ("Bioseq-set.seq-set");