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

« back to all changes in this revision

Viewing changes to demo/scantest.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
*
26
26
* File Name:  scantest.c
27
27
*
28
 
* Author:  Kans, Schuler, Ostell
 
28
* Author:  Kans
29
29
*
30
30
* Version Creation Date:   1/20/95
31
31
*
32
 
* $Revision: 6.0 $
 
32
* $Revision: 6.3 $
33
33
*
34
34
* File Description: 
35
 
*       scans through sequence records on the Entrez discs
 
35
*       template for custom scans of ASN.1 release files
 
36
*       (was - scans through sequence records on the Entrez discs)
36
37
*
37
38
* Modifications:  
38
39
* --------------------------------------------------------------------------
43
44
* ==========================================================================
44
45
*/
45
46
 
46
 
#ifndef _NEW_CdEntrez_
47
 
#define _NEW_CdEntrez_
48
 
#endif
49
 
 
50
47
#include <ncbi.h>
51
 
#include <casn.h>
52
 
#include <accentr.h>
53
 
#include <cdromlib.h>
54
 
#include <seqport.h>
55
48
#include <objall.h>
56
 
 
57
 
#define CHARSPERLINE  50
58
 
 
59
 
typedef struct expstruct {
60
 
  FILE      *fp;
61
 
  AsnIoPtr  aip;
62
 
  Boolean   is_na;
63
 
  Uint1     feat;
64
 
} ExpStruct, PNTR ExpStructPtr;
65
 
 
66
 
static Char root [PATH_MAX];
67
 
static EntrezInfoPtr eip;
68
 
static EntrezDivInfo *div_info;
69
 
 
70
 
static Boolean  scanDNA = FALSE;
71
 
static Boolean  scanPRT = FALSE;
72
 
static Boolean  scanCDS = FALSE;
73
 
 
74
 
static void PrintSequence (BioseqPtr bsp, SeqFeatPtr sfp,
75
 
                           FILE *fp, Boolean is_na)
76
 
 
77
 
{
78
 
  Char        buffer [255];
79
 
  Uint1       code;
80
 
  Int2        count;
81
 
  Uint1       repr;
82
 
  Uint1       residue;
83
 
  SeqPortPtr  spp;
84
 
  CharPtr     title;
85
 
  CharPtr     tmp;
86
 
 
87
 
  if (bsp != NULL && fp != NULL) {
88
 
    if ((Boolean) ISA_na (bsp->mol) == is_na) {
89
 
      repr = Bioseq_repr (bsp);
90
 
      if (repr == Seq_repr_raw || repr == Seq_repr_const) {
91
 
        title = BioseqGetTitle (bsp);
92
 
        tmp = StringMove (buffer, ">");
93
 
        tmp = SeqIdPrint (bsp->id, tmp, PRINTID_FASTA_LONG);
94
 
        tmp = StringMove (tmp, " ");
95
 
        StringNCpy (tmp, title, 200);
96
 
        fprintf (fp, "%s\n", buffer);
97
 
        if (is_na) {
98
 
          code = Seq_code_iupacna;
99
 
        } else {
100
 
          code = Seq_code_iupacaa;
101
 
        }
102
 
        if (sfp != NULL) {
103
 
          spp = SeqPortNewByLoc (sfp->location, code);
104
 
        } else {
105
 
          spp = SeqPortNew (bsp, 0, -1, 0, code);
106
 
        }
107
 
        if (spp != NULL) {
108
 
          count = 0;
109
 
          while ((residue = SeqPortGetResidue (spp)) != SEQPORT_EOF) {
110
 
            if (! IS_residue (residue)) {
111
 
              buffer [count] = '\0';
112
 
              fprintf (fp, "%s\n", buffer);
113
 
              count = 0;
114
 
              switch (residue) {
115
 
                case SEQPORT_VIRT :
116
 
                  fprintf (fp, "[Gap]\n");
117
 
                  break;
118
 
                case SEQPORT_EOS :
119
 
                  fprintf (fp, "[EOS]\n");
120
 
                  break;
121
 
                default :
122
 
                  fprintf (fp, "[Invalid Residue]\n");
123
 
                  break;
124
 
              }
125
 
            } else {
126
 
              buffer [count] = residue;
127
 
              count++;
128
 
              if (count >= CHARSPERLINE) {
129
 
                buffer [count] = '\0';
130
 
                fprintf (fp, "%s\n", buffer);
131
 
                count = 0;
132
 
              }
133
 
            }
134
 
          }
135
 
          if (count != 0) {
136
 
            buffer [count] = '\0';
137
 
            fprintf (fp, "%s\n", buffer);
138
 
          }
139
 
          SeqPortFree (spp);
140
 
        }
141
 
      }
142
 
    }
143
 
  }
144
 
}
145
 
 
146
 
static void LIBCALLBACK GetSeqFeat (AsnExpOptStructPtr aeosp)
147
 
 
148
 
{
149
 
  BioseqPtr     bsp;
150
 
  ExpStructPtr  esp;
151
 
  SeqFeatPtr    sfp;
152
 
 
153
 
  if (aeosp->dvp->intvalue == START_STRUCT) {
154
 
    esp = (ExpStructPtr) aeosp->data;
155
 
    sfp = (SeqFeatPtr) aeosp->the_struct;
156
 
    if (esp != NULL && esp->fp != NULL && sfp != NULL &&
157
 
        sfp->data.choice == esp->feat) {
158
 
      bsp = BioseqFind (SeqLocId (sfp->location));
159
 
      if (bsp != NULL) {
160
 
        PrintSequence (bsp, sfp, esp->fp, esp->is_na);
161
 
      }
162
 
    }
163
 
  }
164
 
}
165
 
 
166
 
static void SeqEntryToFeat (SeqEntryPtr sep, FILE *fp,
167
 
                            Boolean is_na, Uint1 feat)
168
 
 
169
 
{
170
 
  AsnExpOptPtr  aeop;
171
 
  AsnIoPtr      aip;
172
 
  ExpStructPtr  esp;
173
 
 
174
 
  if (sep != NULL && fp != NULL) {
175
 
    esp = MemNew (sizeof (ExpStruct));
176
 
    if (esp != NULL) {
177
 
      aip = AsnIoNullOpen ();
178
 
      if (aip != NULL) {
179
 
        esp->fp = fp;
180
 
        esp->aip = AsnIoNew (ASNIO_TEXT_OUT, fp, NULL, NULL, NULL);
181
 
        esp->is_na = is_na;
182
 
        esp->feat = feat;
183
 
        aeop = AsnExpOptNew (aip, "Seq-feat", (Pointer) esp, GetSeqFeat);
184
 
        if (aeop != NULL) {
185
 
          SeqEntryAsnWrite (sep, aip, NULL);
186
 
          fflush (fp);
187
 
          AsnExpOptFree (aip, aeop);
188
 
        }
189
 
        AsnIoClose (aip);
190
 
      }
191
 
      MemFree (esp);
192
 
    }
193
 
  }
194
 
}
195
 
 
196
 
static void LIBCALLBACK GetFastaSeq (SeqEntryPtr sep, Pointer data,
197
 
                         Int4 index, Int2 indent)
198
 
 
199
 
{
200
 
  BioseqPtr     bsp;
201
 
  ExpStructPtr  esp;
202
 
 
203
 
  if (IS_Bioseq (sep)) {
204
 
    bsp = (BioseqPtr) sep->data.ptrvalue;
205
 
    esp = (ExpStructPtr) data;
206
 
    if (bsp != NULL && esp != NULL && esp->fp != NULL) {
207
 
      PrintSequence (bsp, NULL, esp->fp, esp->is_na);
208
 
    }
209
 
  }
210
 
}
211
 
 
212
 
static void SeqEntryScan (SeqEntryPtr sep, FILE *fp, Boolean is_na)
213
 
 
214
 
{
215
 
  ExpStruct  es;
216
 
 
217
 
  if (sep != NULL && fp != NULL) {
218
 
    es.fp = fp;
219
 
    es.aip = NULL;
220
 
    es.is_na = is_na;
221
 
    es.feat = 0;
222
 
    SeqEntryExplore (sep, (Pointer) &es, GetFastaSeq);
223
 
  }
224
 
}
225
 
 
226
 
static void ProcessSeqEntry (SeqEntryPtr sep, FILE *fp)
227
 
 
228
 
{
229
 
  if (sep != NULL && fp != NULL) {
230
 
    if (scanDNA) {
231
 
      SeqEntryScan (sep, fp, TRUE);
232
 
    } else if (scanPRT) {
233
 
      SeqEntryScan (sep, fp, FALSE);
234
 
    } else if (scanCDS) {
235
 
      SeqEntryToFeat (sep, fp, TRUE, 3);
236
 
    }
237
 
  }
238
 
}
239
 
 
240
 
typedef struct filelist {
241
 
  Int2                  cdnum;
242
 
  CharPtr               fdir;
243
 
  CharPtr               fname;
244
 
  struct filelist PNTR  next;
245
 
} FileList, PNTR FileListPtr;
246
 
 
247
 
static void ProcessFile (FileListPtr flp, CharPtr root, CharPtr outputfile)
248
 
 
249
 
{
250
 
  CASN_Handle  casnh;
251
 
  FILE         *fp;
252
 
  Char         path [PATH_MAX];
253
 
  SeqEntryPtr  sep;
254
 
  CASN_Type    type;
255
 
 
256
 
  if (flp != NULL) {
257
 
    fp = FileOpen (outputfile, "a");
258
 
    if (fp != NULL) {
259
 
      StringCpy (path, root);
260
 
      FileBuildPath (path, flp->fdir, NULL);
261
 
      FileBuildPath (path, NULL, flp->fname);
262
 
      if ((casnh = CASN_Open (path)) != NULL) {
263
 
        if (scanPRT) {
264
 
          type = CASN_Type_aa;
265
 
        } else {
266
 
          type = CASN_Type_nt;
267
 
        }
268
 
        if (CASN_DocType (casnh) == type) {
269
 
          while ((sep = CASN_NextSeqEntry (casnh)) != NULL) {
270
 
            ProcessSeqEntry (sep, fp);
271
 
            SeqEntryFree (sep);
272
 
          }
273
 
        }
274
 
        CASN_Close (casnh);
275
 
      }
276
 
      FileClose (fp);
277
 
    } else {
278
 
      Message (MSG_FATAL, "Unable to reopen output file");
279
 
    }
280
 
  }
281
 
}
282
 
 
283
 
static void ProcessFileList (FileListPtr flp, CharPtr outputfile)
284
 
 
285
 
{
286
 
  Int2         device;
287
 
  FileListPtr  next;
288
 
  Char         root [PATH_MAX];
289
 
 
290
 
  if (flp != NULL) {
291
 
    root [0] = '\0';
292
 
    device = flp->cdnum;
293
 
    flp = flp->next;
294
 
    while (flp != NULL) {
295
 
      next = flp->next;
296
 
      if (device != flp->cdnum) {
297
 
        if (! CdMountEntrezVolume (flp->cdnum, root, sizeof (root))) {
298
 
          Message (MSG_FATAL, "CdMountEntrezVolume failed");
299
 
          root [0] = '\0';
300
 
        }
301
 
      }
302
 
      ProcessFile (flp, root, outputfile);
303
 
      device = flp->cdnum;
304
 
      flp = next;
305
 
    }
306
 
  }
307
 
}
308
 
 
309
 
static FileListPtr FileListNew (FileListPtr flp, Int2 cdnum,
310
 
                                CharPtr fdir, CharPtr fname)
311
 
 
312
 
{
313
 
  FileListPtr  newnode;
314
 
 
315
 
  newnode = (FileListPtr) MemNew (sizeof (FileList));
316
 
  if (newnode != NULL) {
317
 
    if (flp != NULL) {
318
 
      while (flp->next != NULL && flp->next->cdnum <= cdnum) {
319
 
        flp = flp->next;
320
 
      }
321
 
      newnode->next = flp->next;
322
 
      flp->next = newnode;
323
 
    }
324
 
    newnode->cdnum = cdnum;
325
 
    if (fdir != NULL && *fdir != '\0') {
326
 
      newnode->fdir = StringSave (fdir);
327
 
    }
328
 
    if (fname != NULL && *fname != '\0') {
329
 
      newnode->fname = StringSave (fname);
330
 
    }
331
 
  }
332
 
  return newnode;
333
 
}
334
 
 
335
 
static Boolean LIBCALLBACK EnumerateFiles (int cdnum, const char *fdir,
336
 
                                           const char *fname, long fsize,
337
 
                                           void *opaque_data)
338
 
 
339
 
{
340
 
  FileListPtr      flp;
341
 
  FileListPtr PNTR head;
342
 
 
343
 
  head = (FileListPtr PNTR) opaque_data;
344
 
  flp = NULL;
345
 
  if (head != NULL) {
346
 
    flp = FileListNew (*head, (Int2) cdnum, (CharPtr) fdir, (CharPtr) fname);
347
 
    if (*head == NULL) {
348
 
      *head = flp;
349
 
    }
350
 
  } else {
351
 
    flp = FileListNew (NULL, (Int2) cdnum, (CharPtr) fdir, (CharPtr) fname);
352
 
  }
353
 
  return TRUE;
354
 
}
355
 
 
356
 
#define NUMARGS 4
357
 
 
358
 
Args myargs [NUMARGS] = {
359
 
  {"Scan DNA", "F", NULL, NULL, TRUE, 'd', ARG_BOOLEAN, 0.0, 0, NULL},
360
 
  {"Scan Protein", "F", NULL, NULL, TRUE, 'p', ARG_BOOLEAN, 0.0, 0, NULL},
361
 
  {"Scan Coding Regions", "F", NULL, NULL, TRUE, 'c', ARG_BOOLEAN, 0.0, 0, NULL},
362
 
  {"Output File", "stdout", NULL, NULL, FALSE, 'o', ARG_FILE_OUT, 0.0, 0, NULL}
 
49
#include <objsset.h>
 
50
#include <objsub.h>
 
51
#include <objfdef.h>
 
52
#include <sequtil.h>
 
53
#include <sqnutils.h>
 
54
#include <explore.h>
 
55
 
 
56
typedef struct appflags {
 
57
  Boolean  binary;
 
58
  Boolean  compressed;
 
59
  Boolean  verbose;
 
60
  FILE     *fp;
 
61
  Char     id [64];
 
62
} AppFlagData, PNTR AppFlagPtr;
 
63
 
 
64
static void DoOneUser (UserObjectPtr uop, Pointer userdata)
 
65
 
 
66
{
 
67
  AppFlagPtr   afp;
 
68
  Char         buf [128];
 
69
  ObjectIdPtr  oip;
 
70
 
 
71
  if (uop == NULL) return;
 
72
  afp = (AppFlagPtr) userdata;
 
73
  if (afp == NULL) return;
 
74
 
 
75
  buf [0] = '\0';
 
76
  if (StringDoesHaveText (uop->_class)) {
 
77
    StringCat (buf, uop->_class);
 
78
  }
 
79
  StringCat (buf, "                                ");
 
80
  buf [30] = '\0';
 
81
  fprintf (afp->fp, "%s", buf);
 
82
 
 
83
  buf [0] = '\0';
 
84
  oip = uop->type;
 
85
  if (oip != NULL) {
 
86
    if (StringDoesHaveText (oip->str)) {
 
87
      StringCat (buf, oip->str);
 
88
    } else if (oip->id > 0) {
 
89
      sprintf (buf, "%ld", (long) oip->id);
 
90
    }
 
91
  }
 
92
  StringCat (buf, "                                ");
 
93
  buf [30] = '\0';
 
94
  fprintf (afp->fp, "%s", buf);
 
95
 
 
96
  if (afp->verbose) {
 
97
    fprintf (afp->fp, "     %s", afp->id);
 
98
  }
 
99
 
 
100
  fprintf (afp->fp, "\n");
 
101
  fflush (afp->fp);
 
102
}
 
103
 
 
104
static void DoOneDescriptor (SeqDescrPtr sdp, Pointer userdata)
 
105
 
 
106
{
 
107
  AppFlagPtr     afp;
 
108
  UserObjectPtr  uop;
 
109
 
 
110
  if (sdp == NULL || sdp->choice != Seq_descr_user) return;
 
111
  afp = (AppFlagPtr) userdata;
 
112
  if (afp == NULL) return;
 
113
 
 
114
  uop = (UserObjectPtr) sdp->data.ptrvalue;
 
115
  if (uop == NULL) return;
 
116
 
 
117
  VisitUserObjectsInUop (uop, (Pointer) afp, DoOneUser);
 
118
}
 
119
 
 
120
static void DoOneFeature (SeqFeatPtr sfp, Pointer userdata)
 
121
 
 
122
{
 
123
  AppFlagPtr     afp;
 
124
  UserObjectPtr  uop;
 
125
 
 
126
  if (sfp == NULL) return;
 
127
  afp = (AppFlagPtr) userdata;
 
128
  if (afp == NULL) return;
 
129
 
 
130
  uop = sfp->ext;
 
131
  if (uop != NULL) {
 
132
    VisitUserObjectsInUop (uop, (Pointer) afp, DoOneUser);
 
133
  }
 
134
 
 
135
  for (uop = sfp->exts; uop != NULL; uop = uop->next) {
 
136
    VisitUserObjectsInUop (uop, (Pointer) afp, DoOneUser);
 
137
  }
 
138
}
 
139
 
 
140
static void DoRecord (SeqEntryPtr sep, Pointer userdata)
 
141
 
 
142
{
 
143
  AppFlagPtr   afp;
 
144
  BioseqPtr    fbsp;
 
145
  SeqEntryPtr  fsep;
 
146
 
 
147
  if (sep == NULL) return;
 
148
  afp = (AppFlagPtr) userdata;
 
149
  if (afp == NULL) return;
 
150
 
 
151
  fsep = FindNthBioseq (sep, 1);
 
152
  if (fsep == NULL) return;
 
153
  fbsp = (BioseqPtr) fsep->data.ptrvalue;
 
154
  if (fbsp == NULL) return;
 
155
 
 
156
  SeqIdWrite (fbsp->id, afp->id, PRINTID_FASTA_LONG, 64);
 
157
 
 
158
  VisitDescriptorsInSep (sep, (Pointer) afp, DoOneDescriptor);
 
159
  VisitFeaturesInSep (sep, (Pointer) afp, DoOneFeature);
 
160
}
 
161
 
 
162
static void ProcessOneRecord (
 
163
  CharPtr filename,
 
164
  Pointer userdata
 
165
)
 
166
 
 
167
{
 
168
  AppFlagPtr  afp;
 
169
 
 
170
  if (StringHasNoText (filename)) return;
 
171
  afp = (AppFlagPtr) userdata;
 
172
  if (afp == NULL) return;
 
173
 
 
174
  if (StringStr (filename, "gbest") != NULL ||
 
175
      StringStr (filename, "gbgss") != NULL ||
 
176
      StringStr (filename, "gbhtg") != NULL) {
 
177
    printf ("Skipping %s\n", filename);
 
178
    return;
 
179
  }
 
180
 
 
181
  printf ("%s\n", filename);
 
182
  fflush (stdout);
 
183
 
 
184
  fprintf (afp->fp, "%s\n", filename);
 
185
  fflush (afp->fp);
 
186
 
 
187
  ScanBioseqSetRelease (filename, afp->binary, afp->compressed, (Pointer) afp, DoRecord);
 
188
 
 
189
  fprintf (afp->fp, "\n");
 
190
  fflush (afp->fp);
 
191
}
 
192
 
 
193
#define p_argInputPath    0
 
194
#define i_argInputFile    1
 
195
#define o_argOutputFile   2
 
196
#define f_argFilter       3
 
197
#define x_argSuffix       4
 
198
#define u_argRecurse      5
 
199
#define b_argBinary       6
 
200
#define c_argCompressed   7
 
201
#define v_argVerbose      8
 
202
 
 
203
Args myargs [] = {
 
204
  {"Path to Files", NULL, NULL, NULL,
 
205
    TRUE, 'p', ARG_STRING, 0.0, 0, NULL},
 
206
  {"Input File Name", NULL, NULL, NULL,
 
207
    TRUE, 'i', ARG_FILE_IN, 0.0, 0, NULL},
 
208
  {"Output File Name", NULL, NULL, NULL,
 
209
    TRUE, 'o', ARG_FILE_OUT, 0.0, 0, NULL},
 
210
  {"Substring Filter", NULL, NULL, NULL,
 
211
    TRUE, 'f', ARG_STRING, 0.0, 0, NULL},
 
212
  {"File Selection Suffix", ".aso", NULL, NULL,
 
213
    TRUE, 'x', ARG_STRING, 0.0, 0, NULL},
 
214
  {"Recurse", "F", NULL, NULL,
 
215
    TRUE, 'u', ARG_BOOLEAN, 0.0, 0, NULL},
 
216
  {"Bioseq-set is Binary", "F", NULL, NULL,
 
217
    TRUE, 'b', ARG_BOOLEAN, 0.0, 0, NULL},
 
218
  {"Bioseq-set is Compressed", "F", NULL, NULL,
 
219
    TRUE, 'c', ARG_BOOLEAN, 0.0, 0, NULL},
 
220
  {"Verbose", "F", NULL, NULL,
 
221
    TRUE, 'v', ARG_BOOLEAN, 0.0, 0, NULL},
363
222
};
364
223
 
365
224
extern Int2 Main (void)
366
225
 
367
226
{
368
 
  Char         div [8];
369
 
  FileListPtr  flp;
370
 
  FILE         *fp;
371
 
  Int2         i;
372
 
  Boolean      is_network;
373
 
  FileListPtr  next;
374
 
  Int2         sum;
375
 
 
376
 
  if (GetArgs ("Scantest", NUMARGS, myargs)) {
377
 
    scanDNA = (Boolean) myargs [0].intvalue;
378
 
    scanPRT = (Boolean) myargs [1].intvalue;
379
 
    scanCDS = (Boolean) myargs [2].intvalue;
380
 
    sum = 0;
381
 
    for (i = 0; i < 3; i++) {
382
 
      sum += myargs [i].intvalue;
383
 
    }
384
 
    if (sum == 1) {
385
 
      if (AllObjLoad () && SeqCodeSetLoad ()) {
386
 
        if (EntrezInit ("scantest", FALSE, &is_network)) {
387
 
          if (is_network) {
388
 
            Message (MSG_FATAL, "Network service does not allow scanning");
389
 
          } else {
390
 
            eip = EntrezGetInfo ();
391
 
            if (eip != NULL && eip->div_info != NULL) {
392
 
              flp = FileListNew (NULL, INT2_MIN, NULL, NULL);
393
 
              if (flp != NULL) {
394
 
                div_info = eip->div_info;
395
 
                for (i = 0; i < eip->div_count; i++) {
396
 
                  StringNCpy (div, div_info [i].tag, sizeof (div) - 1);
397
 
                  if (scanPRT) {
398
 
                    CdEnumFiles (CdDir_rec, TYP_AA, div, EnumerateFiles, &flp);
399
 
                  } else {
400
 
                    CdEnumFiles (CdDir_rec, TYP_NT, div, EnumerateFiles, &flp);
401
 
                  }
402
 
                }
403
 
                fp = FileOpen (myargs[3].strvalue, "w");
404
 
                if (fp != NULL) {
405
 
                  FileClose (fp);
406
 
                  ProcessFileList (flp, myargs[3].strvalue);
407
 
                } else {
408
 
                  Message (MSG_FATAL, "Unable to create output file");
409
 
                }
410
 
                while (flp != NULL) {
411
 
                  next = flp->next;
412
 
                  MemFree (flp->fdir);
413
 
                  MemFree (flp->fname);
414
 
                  MemFree (flp);
415
 
                  flp = next;
416
 
                }
417
 
                flp = NULL;
418
 
              } else {
419
 
                Message (MSG_FATAL, "Unable to allocate file list pointer");
420
 
              }
421
 
            } else {
422
 
              Message (MSG_FATAL, "Unable to obtain Entrez Info");
423
 
            }
424
 
          }
425
 
          EntrezFini ();
426
 
        } else {
427
 
          Message (MSG_FATAL, "Unable to connect to Entrez service");
428
 
        }
429
 
      } else {
430
 
        Message (MSG_FATAL, "Unable to load parse tables");
431
 
      }
432
 
    } else {
433
 
      Message (MSG_FATAL, "You must choose one of the three options");
434
 
    }
435
 
  }
 
227
  AppFlagData  afd;
 
228
  Boolean      dorecurse;
 
229
  CharPtr      filter, infile, outfile, directory, suffix;
 
230
 
 
231
  /* standard setup */
 
232
 
 
233
  ErrSetFatalLevel (SEV_MAX);
 
234
  ErrClearOptFlags (EO_SHOW_USERSTR);
 
235
  ErrSetLogfile ("stderr", ELOG_APPEND);
 
236
  UseLocalAsnloadDataAndErrMsg ();
 
237
  ErrPathReset ();
 
238
 
 
239
  if (! AllObjLoad ()) {
 
240
    Message (MSG_FATAL, "AllObjLoad failed");
 
241
    return 1;
 
242
  }
 
243
  if (! SubmitAsnLoad ()) {
 
244
    Message (MSG_FATAL, "SubmitAsnLoad failed");
 
245
    return 1;
 
246
  }
 
247
  if (! FeatDefSetLoad ()) {
 
248
    Message (MSG_FATAL, "FeatDefSetLoad failed");
 
249
    return 1;
 
250
  }
 
251
  if (! SeqCodeSetLoad ()) {
 
252
    Message (MSG_FATAL, "SeqCodeSetLoad failed");
 
253
    return 1;
 
254
  }
 
255
  if (! GeneticCodeTableLoad ()) {
 
256
    Message (MSG_FATAL, "GeneticCodeTableLoad failed");
 
257
    return 1;
 
258
  }
 
259
 
 
260
  /* process command line arguments */
 
261
 
 
262
  if (! GetArgs ("scantest", sizeof (myargs) / sizeof (Args), myargs)) {
 
263
    return 0;
 
264
  }
 
265
 
 
266
  MemSet ((Pointer) &afd, 0, sizeof (AppFlagData));
 
267
 
 
268
  directory = (CharPtr) myargs [p_argInputPath].strvalue;
 
269
  infile = (CharPtr) myargs [i_argInputFile].strvalue;
 
270
  outfile = (CharPtr) myargs [o_argOutputFile].strvalue;
 
271
  filter = (CharPtr) myargs [f_argFilter].strvalue;
 
272
  suffix = (CharPtr) myargs [x_argSuffix].strvalue;
 
273
  dorecurse = (Boolean) myargs [u_argRecurse].intvalue;
 
274
  afd.binary = (Boolean) myargs [b_argBinary].intvalue;
 
275
  afd.compressed = (Boolean) myargs [c_argCompressed].intvalue;
 
276
  afd.verbose = (Boolean) myargs[v_argVerbose].intvalue;
 
277
 
 
278
  afd.fp = FileOpen (outfile, "w");
 
279
  if (afd.fp == NULL) {
 
280
    return 0;
 
281
  }
 
282
 
 
283
  if (StringDoesHaveText (directory)) {
 
284
 
 
285
    DirExplore (directory, NULL, suffix, dorecurse, ProcessOneRecord, (Pointer) &afd);
 
286
 
 
287
  } else if (StringDoesHaveText (infile)) {
 
288
 
 
289
    ProcessOneRecord (infile, &afd);
 
290
  }
 
291
 
 
292
  FileClose (afd.fp);
 
293
 
436
294
  return 0;
437
295
}