~ubuntu-branches/ubuntu/quantal/ncbi-tools6/quantal

« back to all changes in this revision

Viewing changes to demo/asndisc.c

Tags: upstream-6.1.20081116a
ImportĀ upstreamĀ versionĀ 6.1.20081116a

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   1/23/07
31
31
*
32
 
* $Revision: 1.20 $
 
32
* $Revision: 1.24 $
33
33
*
34
34
* File Description:
35
35
*
80
80
  CharPtr  output_dir;
81
81
  FILE     *outfp;
82
82
  Int4     numrecords;
83
 
  DiscReportOutputConfigData ocd;
84
 
  DiscrepancyConfigData dcd;
85
83
  ValNodePtr            sep_list;
86
84
  ValNodePtr            bsplist;
 
85
 
 
86
  GlobalDiscrepReportPtr global_report;
87
87
} DRFlagData, PNTR DRFlagPtr;
88
88
 
89
89
#ifdef INTERNAL_NCBI_ASNDISC
493
493
  return rsult;
494
494
}
495
495
 
496
 
static void ProcessSeqEntryList (DRFlagPtr drfp, CharPtr filename)
 
496
 
 
497
static void ReleaseDiscrepancyReportSeqEntries (DRFlagPtr drfp)
497
498
{
498
 
  ValNodePtr  discrepancy_list, vnp;
 
499
  ValNodePtr vnp;
 
500
  SeqEntryPtr sep;
499
501
  ObjMgrPtr   omp;
500
 
  SeqEntryPtr sep;
501
 
  FILE        *ofp = NULL;
502
 
  Boolean     need_ofp_close = FALSE;
503
 
  Char        path [PATH_MAX];
504
 
  CharPtr     ptr;
505
 
 
506
 
  if (drfp == NULL || drfp->sep_list == NULL) return;
507
 
 
508
 
  if (drfp->outfp == NULL) {
509
 
    if (StringDoesHaveText (drfp->output_dir)) {
510
 
      if (StringLen (drfp->output_dir) > PATH_MAX) {
511
 
        Message (MSG_ERROR, "Unable to generate output file - path name is too long");
512
 
        return;
513
 
      }
514
 
      StringCpy (path, drfp->output_dir);
515
 
#ifdef OS_WINNT
516
 
      ptr = StringRChr (filename, '\\');
517
 
      if (path[StringLen(path) - 1] != '\\') {
518
 
        StringCat (path, "\\");
519
 
      }
520
 
#else
521
 
      ptr = StringRChr (filename, '/');
522
 
      if (path[StringLen(path) - 1] != '/') {
523
 
        StringCat (path, "/");
524
 
      }
525
 
#endif;
526
 
      if (ptr == NULL) {
527
 
        StringNCat (path, filename, PATH_MAX - StringLen(path) - 1);
528
 
      } else {
529
 
        StringNCat (path, ptr + 1, PATH_MAX - StringLen(path) - 1);
530
 
      }
531
 
    } else {
532
 
      StringNCpy_0 (path, filename, sizeof (path));
533
 
    }
534
 
    ptr = StringRChr (path, '.');
535
 
    if (ptr != NULL) {
536
 
      *ptr = '\0';
537
 
    }
538
 
    if (StringDoesHaveText (drfp->output_suffix)) {
539
 
      StringNCat (path, drfp->output_suffix, PATH_MAX - StringLen(path) - 1);
540
 
      path[PATH_MAX - 1] = 0;
541
 
    } else {
542
 
      StringCat (path, ".dr");
543
 
    }
544
 
    if (drfp->outfp == NULL) {
545
 
      ofp = FileOpen (path, "w");
546
 
      need_ofp_close = TRUE;
547
 
    } else {
548
 
      ofp = drfp->outfp;
549
 
    }
550
 
  } else {
551
 
    ofp = drfp->outfp;
 
502
 
 
503
  if (drfp == NULL) {
 
504
    return;
552
505
  }
553
506
 
554
 
  discrepancy_list = CollectDiscrepancies (&(drfp->dcd), drfp->sep_list, taxlookup);
555
 
  WriteAsnDiscReport (discrepancy_list, ofp, &(drfp->ocd), TRUE);
556
 
  discrepancy_list = FreeClickableList (discrepancy_list);
557
507
  for (vnp = drfp->sep_list; vnp != NULL; vnp = vnp->next) {
558
508
    sep = vnp->data.ptrvalue;
559
509
    SeqEntryFree (sep);
566
516
  SeqEntrySetScope (NULL);
567
517
  drfp->sep_list = ValNodeFree (drfp->sep_list);
568
518
  
569
 
  drfp->ocd.filename_list = FreeFilenameList (drfp->ocd.filename_list);
570
 
 
571
519
  drfp->bsplist = UnlockFarComponents (drfp->bsplist);
572
 
 
573
 
  if (ofp != NULL && need_ofp_close) {
574
 
    FileClose (ofp);
575
 
  }
 
520
}
 
521
 
 
522
 
 
523
static void ProcessSeqEntryList (DRFlagPtr drfp, CharPtr filename)
 
524
{
 
525
  ValNodePtr  discrepancy_list;
 
526
  FILE        *ofp = NULL;
 
527
  Char        path [PATH_MAX];
 
528
  CharPtr     ptr;
 
529
 
 
530
  if (drfp == NULL || drfp->sep_list == NULL) return;
 
531
 
 
532
  if (StringDoesHaveText (drfp->output_dir)) {
 
533
    if (StringLen (drfp->output_dir) > PATH_MAX) {
 
534
      Message (MSG_ERROR, "Unable to generate output file - path name is too long");
 
535
      return;
 
536
    }
 
537
    StringCpy (path, drfp->output_dir);
 
538
#ifdef OS_WINNT
 
539
    ptr = StringRChr (filename, '\\');
 
540
    if (path[StringLen(path) - 1] != '\\') {
 
541
      StringCat (path, "\\");
 
542
    }
 
543
#else
 
544
    ptr = StringRChr (filename, '/');
 
545
    if (path[StringLen(path) - 1] != '/') {
 
546
      StringCat (path, "/");
 
547
    }
 
548
#endif;
 
549
    if (ptr == NULL) {
 
550
      StringNCat (path, filename, PATH_MAX - StringLen(path) - 1);
 
551
    } else {
 
552
      StringNCat (path, ptr + 1, PATH_MAX - StringLen(path) - 1);
 
553
    }
 
554
  } else {
 
555
    StringNCpy_0 (path, filename, sizeof (path));
 
556
  }
 
557
  ptr = StringRChr (path, '.');
 
558
  if (ptr != NULL) {
 
559
    *ptr = '\0';
 
560
  }
 
561
  if (StringDoesHaveText (drfp->output_suffix)) {
 
562
    StringNCat (path, drfp->output_suffix, PATH_MAX - StringLen(path) - 1);
 
563
    path[PATH_MAX - 1] = 0;
 
564
  } else {
 
565
    StringCat (path, ".dr");
 
566
  }
 
567
  ofp = FileOpen (path, "w");
 
568
 
 
569
  discrepancy_list = CollectDiscrepancies (drfp->global_report->test_config, drfp->sep_list, taxlookup);
 
570
  WriteAsnDiscReport (discrepancy_list, ofp, drfp->global_report->output_config, TRUE);
 
571
  discrepancy_list = FreeClickableList (discrepancy_list);
 
572
 
 
573
  FileClose (ofp);
576
574
}
577
575
 
578
576
 
681
679
 
682
680
    if (sep != NULL) {
683
681
      ValNodeAddPointer (&(drfp->sep_list), 0, sep);
684
 
      ValNodeAddInt (&(drfp->ocd.filename_list), FILENAME_LIST_ENTITY_ID_ITEM, (Int4) entityID);
685
 
      ValNodeAddPointer (&(drfp->ocd.filename_list), FILENAME_LIST_FILENAME_ITEM, StringSave (filename));
686
682
 
687
683
      if (drfp->lock) {
688
684
        bsplist_next = DoLockFarComponents (sep, drfp);
883
879
 
884
880
}
885
881
 
886
 
static void ProcessOneRecord (
887
 
  CharPtr filename,
888
 
  Pointer userdata
889
 
)
890
 
 
 
882
 
 
883
static void ProcessSeqEntryListWithCollation (GlobalDiscrepReportPtr g, ValNodePtr sep_list, CharPtr filename)
 
884
{
 
885
  ValNodePtr  vnp;
 
886
  SeqEntryPtr sep;
 
887
 
 
888
  if (g == NULL || sep_list == NULL) return;
 
889
 
 
890
  for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
 
891
    sep = vnp->data.ptrvalue;
 
892
    AddSeqEntryToGlobalDiscrepReport (sep, g, filename);
 
893
  }
 
894
 
 
895
}
 
896
 
 
897
 
 
898
static void ProcessOneRecord (CharPtr filename, Pointer userdata)
891
899
{
892
900
  DRFlagPtr  drfp;
893
901
 
899
907
  } else {
900
908
    ProcessSingleRecord (filename, drfp);
901
909
  }
 
910
 
902
911
  if (drfp->outfp == NULL) {
903
912
    ProcessSeqEntryList (drfp, filename);
 
913
  } else {
 
914
    ProcessSeqEntryListWithCollation (drfp->global_report, drfp->sep_list, filename);
904
915
  }
 
916
  ReleaseDiscrepancyReportSeqEntries (drfp);
905
917
}
906
918
 
 
919
 
907
920
/* Args structure contains command-line arguments */
908
921
 
909
922
typedef enum {
928
941
  T_argThreads,
929
942
  X_argExpandCategories,
930
943
  S_argSummaryReport,
 
944
  B_argBigSequenceReport,
931
945
  C_argMaxCount
932
946
} DRFlagNum;
933
947
 
989
1003
    TRUE, 'X', ARG_STRING, 0.0, 0, NULL},
990
1004
  {"Summary Report", "F", NULL, NULL,
991
1005
    TRUE, 'S', ARG_BOOLEAN, 0.0, 0, NULL},
 
1006
  {"Big Sequence Report", "F", NULL, NULL,
 
1007
  TRUE, 'B', ARG_BOOLEAN, 0.0, 0, NULL},
992
1008
  {"Max Count", "0", NULL, NULL,
993
1009
    TRUE, 'C', ARG_INT, 0.0, 0, NULL},
994
1010
};
1016
1032
  return text;
1017
1033
}
1018
1034
 
 
1035
 
1019
1036
Int2 Main (void)
1020
1037
 
1021
1038
{
1024
1041
  CharPtr      enabled_list, disabled_list, err_msg;
1025
1042
  Boolean      batch, binary, compressed, dorecurse,
1026
1043
               indexed, local, lock, remote, usethreads;
1027
 
  Int2         type = 0, k;
 
1044
  Int2         type = 0;
1028
1045
  DRFlagData   dfd;
 
1046
  Boolean      big_sequence_report;
1029
1047
 
1030
1048
  /* standard setup */
1031
1049
 
1099
1117
  lock = (Boolean) myargs [l_argLockFar].intvalue;
1100
1118
  usethreads = (Boolean) myargs [T_argThreads].intvalue;
1101
1119
  dfd.farFetchCDSproducts = (Boolean) myargs [Z_argRemoteCDS].intvalue;
1102
 
  ExpandDiscrepancyReportTestsFromString ((CharPtr) myargs [X_argExpandCategories].strvalue, TRUE, &dfd.ocd);
1103
 
  dfd.ocd.summary_report = (Boolean) myargs [S_argSummaryReport].intvalue;
1104
1120
 
1105
1121
  /* set up Discrepancy Report Configuration */
 
1122
  dfd.global_report = GlobalDiscrepReportNew ();
 
1123
  dfd.global_report->test_config = DiscrepancyConfigNew();
 
1124
 
 
1125
  ExpandDiscrepancyReportTestsFromString ((CharPtr) myargs [X_argExpandCategories].strvalue, TRUE, dfd.global_report->output_config);
 
1126
  dfd.global_report->output_config->summary_report = (Boolean) myargs [S_argSummaryReport].intvalue;
 
1127
 
 
1128
  big_sequence_report = (Boolean) myargs [B_argBigSequenceReport].intvalue;
 
1129
 
1106
1130
  enabled_list = (CharPtr) myargs [e_argEnableTests].strvalue;
1107
1131
  disabled_list = (CharPtr) myargs [d_argDisableTests].strvalue;
1108
1132
 
 
1133
 
 
1134
#ifdef INTERNAL_NCBI_ASNDISC
 
1135
  dfd.global_report->taxlookup = CheckTaxNamesAgainstTaxDatabase;
 
1136
#endif
 
1137
  
1109
1138
  err_msg = NULL;
1110
1139
  if (StringDoesHaveText (enabled_list) && StringDoesHaveText (disabled_list)) {
1111
1140
    err_msg = StringSave ("Cannot specify both -e and -d.  Choose -e to enable only a few tests and disable the rest, choose -d to disable only a few tests and enable the rest.");
1112
1141
  } else if (StringDoesHaveText (disabled_list)) {
1113
 
    for (k = 0; k < MAX_DISC_TYPE; k++) {
1114
 
      dfd.dcd.conf_list[k] = TRUE;
 
1142
    if (big_sequence_report) {
 
1143
      ConfigureForBigSequence (dfd.global_report->test_config);
 
1144
    } else {
 
1145
      ConfigureForGenomes (dfd.global_report->test_config);
1115
1146
    }
1116
 
    DisableTRNATests (&(dfd.dcd));
1117
1147
 
1118
1148
    /* now disable tests from string */
1119
 
    err_msg = SetDiscrepancyReportTestsFromString (disabled_list, FALSE, &(dfd.dcd));
 
1149
    err_msg = SetDiscrepancyReportTestsFromString (disabled_list, FALSE, dfd.global_report->test_config);
1120
1150
  } else if (StringDoesHaveText (enabled_list)) {
1121
 
    for (k = 0; k < MAX_DISC_TYPE; k++) {
1122
 
      dfd.dcd.conf_list[k] = FALSE;
 
1151
    if (big_sequence_report) {
 
1152
      ConfigureForBigSequence (dfd.global_report->test_config);
 
1153
    } else {
 
1154
      ConfigureForGenomes (dfd.global_report->test_config);
1123
1155
    }
1124
1156
    /* now enable tests from string */
1125
 
    err_msg = SetDiscrepancyReportTestsFromString (enabled_list, TRUE, &(dfd.dcd));
 
1157
    err_msg = SetDiscrepancyReportTestsFromString (enabled_list, TRUE, dfd.global_report->test_config);
1126
1158
  } else {
1127
 
    /* enable all tests by default */
1128
 
    for (k = 0; k < MAX_DISC_TYPE; k++) {
1129
 
      dfd.dcd.conf_list[k] = TRUE;
 
1159
    if (big_sequence_report) {
 
1160
      ConfigureForBigSequence (dfd.global_report->test_config);
 
1161
    } else {
 
1162
      ConfigureForGenomes (dfd.global_report->test_config);
1130
1163
    }
1131
 
    DisableTRNATests (&(dfd.dcd));
1132
1164
  }
1133
1165
  if (err_msg != NULL) {
1134
1166
    Message (MSG_FATAL, err_msg);
1137
1169
  }
1138
1170
 
1139
1171
  if ((Boolean) myargs[f_argUseFT].intvalue) {
1140
 
    dfd.dcd.use_feature_table_format = TRUE;
1141
 
    dfd.ocd.use_feature_table_format = TRUE;
 
1172
    dfd.global_report->test_config->use_feature_table_format = TRUE;
 
1173
    dfd.global_report->output_config->use_feature_table_format = TRUE;
1142
1174
  }
1143
1175
 
1144
1176
  dfd.maxcount = (Int4) myargs [C_argMaxCount].intvalue;
1226
1258
    AsnIndexedLibFetchEnable (asnidx, TRUE);
1227
1259
  }
1228
1260
 
1229
 
  /* recurse through all files within source directory or subdirectories */
1230
 
 
1231
1261
  if (StringDoesHaveText (directory)) {
1232
 
 
1233
1262
    DirExplore (directory, NULL, suffix, dorecurse, ProcessOneRecord, (Pointer) &dfd);
1234
 
    if (dfd.outfp != NULL) {
1235
 
      ProcessSeqEntryList (&dfd, NULL);
1236
 
    }
1237
1263
 
1238
1264
  } else if (StringDoesHaveText (infile)) {
1239
1265
 
1240
1266
    ProcessOneRecord (infile, (Pointer) &dfd);
1241
 
    if (dfd.outfp != NULL) {
1242
 
      ProcessSeqEntryList (&dfd, NULL);
1243
 
    }
1244
1267
  }
1245
 
 
1246
1268
  if (dfd.outfp != NULL) {
 
1269
    WriteGlobalDiscrepancyReport (dfd.global_report, dfd.outfp);
1247
1270
    FileClose (dfd.outfp);
 
1271
    dfd.outfp = NULL;
1248
1272
  }
1249
1273
 
 
1274
  dfd.global_report = GlobalDiscrepReportFree (dfd.global_report);
 
1275
 
1250
1276
  /* close fetch functions */
1251
1277
 
1252
1278
  if (indexed) {