|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/demo/asnstrip.c |
source navigation diff markup identifier search freetext search file search |
1 /* asnstrip.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information (NCBI)
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government do not place any restriction on its use or reproduction.
13 * We would, however, appreciate having the NCBI and the author cited in
14 * any work or product based on this material
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name: asnstrip.c
27 *
28 * Author: Colleen Bollin
29 *
30 * Version Creation Date: 4/12/07
31 *
32 * $Revision: 1.11 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 *
41 *
42 * ==========================================================================
43 */
44
45 #include <ncbi.h>
46 #include <objall.h>
47 #include <objsset.h>
48 #include <objsub.h>
49 #include <objfdef.h>
50 #include <sequtil.h>
51 #include <gather.h>
52 #include <sqnutils.h>
53 #include <explore.h>
54
55 #define ASNSTRIP_APP_VER "1.0"
56
57 CharPtr ASNSTRIP_APPLICATION = ASNSTRIP_APP_VER;
58
59 typedef struct outputstream {
60 CharPtr results_dir;
61 CharPtr base;
62 CharPtr suffix;
63 CharPtr outfile;
64 CharPtr outsuffix;
65 AsnIoPtr aip;
66 Boolean is_binary;
67 } OutputStreamData, PNTR OutputStreamPtr;
68
69 typedef struct inputstream {
70 CharPtr directory;
71 CharPtr base;
72 CharPtr suffix;
73 Boolean is_binary;
74 Boolean is_seqentry;
75 } InputStreamData, PNTR InputStreamPtr;
76
77 typedef struct asnstream {
78 AsnModulePtr amp;
79 AsnTypePtr atp_se;
80 AsnTypePtr atp_bss;
81 AsnTypePtr atp_bss_se;
82 } AsnStreamData, PNTR AsnStreamPtr;
83
84 typedef struct stripitems {
85 Boolean strip_features;
86 Boolean strip_citsubpubs;
87 Boolean strip_noncitsubpubs;
88 Boolean strip_comment_descriptors;
89 } StripItemsData, PNTR StripItemsPtr;
90
91 static FILE* OpenOneFile (
92 CharPtr directory,
93 CharPtr base,
94 CharPtr suffix
95 )
96
97 {
98 Char file [FILENAME_MAX], path [PATH_MAX];
99
100 if (base == NULL) {
101 base = "";
102 }
103 if (suffix == NULL) {
104 suffix = "";
105 }
106
107 StringNCpy_0 (path, directory, sizeof (path));
108 sprintf (file, "%s%s", base, suffix);
109 FileBuildPath (path, NULL, file);
110
111 return FileOpen (path, "r");
112 }
113
114 static AsnIoPtr AsnIoFromInputStream (
115 InputStreamPtr isp
116 )
117
118 {
119 AsnIoPtr aip;
120 Char file [FILENAME_MAX], path [PATH_MAX];
121 CharPtr read_flag;
122
123 if (isp == NULL) return NULL;
124
125 if (isp->is_binary) {
126 read_flag = "rb";
127 } else {
128 read_flag = "r";
129 }
130
131 if (isp->base == NULL) {
132 aip = AsnIoOpen ("stdin", read_flag);
133 } else {
134 StringNCpy_0 (path, isp->directory, sizeof (path));
135 sprintf (file, "%s%s", isp->base, isp->suffix);
136 FileBuildPath (path, NULL, file);
137 aip = AsnIoOpen (path, read_flag);
138 }
139 return aip;
140 }
141
142
143 static AsnIoPtr AsnIoFromOutputStream (OutputStreamPtr osp)
144 {
145 AsnIoPtr aip;
146 Char file [FILENAME_MAX], path [PATH_MAX];
147 CharPtr write_flag;
148
149 if (osp == NULL) return NULL;
150 if (osp->aip == NULL) {
151 write_flag = osp->is_binary ? "wb" : "w";
152 if (StringDoesHaveText (osp->outfile)) {
153 StringNCpy_0 (path, osp->outfile, sizeof (path));
154 } else {
155 if (osp->base == NULL) {
156 aip = AsnIoOpen ("stdout", write_flag);
157 } else {
158 if (osp->outsuffix == NULL) {
159 osp->outsuffix = "";
160 }
161 StringNCpy_0 (path, osp->results_dir, sizeof (path));
162 sprintf (file, "%s%s%s", osp->base, osp->suffix, osp->outsuffix);
163 FileBuildPath (path, NULL, file);
164 aip = AsnIoOpen (path, write_flag);
165 if (aip == NULL) {
166 Message (MSG_POSTERR, "Unable to write to %s.", path);
167 }
168 }
169 }
170 } else {
171 aip = osp->aip;
172 }
173 return aip;
174 }
175
176 static void WriteOneFile (
177 OutputStreamPtr osp,
178 SeqEntryPtr sep
179 )
180
181 {
182 AsnIoPtr aip;
183
184 aip = AsnIoFromOutputStream (osp);
185 if (aip != NULL) {
186 SeqEntryAsnWrite (sep, aip, NULL);
187 AsnIoFlush (aip);
188 }
189 if (aip != osp->aip) {
190 AsnIoClose (aip);
191 }
192 }
193
194 static void WriteOneSeqSubmitFile (
195 OutputStreamPtr osp,
196 SeqSubmitPtr ssp
197 )
198
199 {
200 AsnIoPtr aip;
201
202 aip = AsnIoFromOutputStream (osp);
203 if (aip != NULL) {
204 SeqSubmitAsnWrite (ssp, aip, NULL);
205 AsnIoFlush (aip);
206 }
207 if (aip != osp->aip) {
208 AsnIoClose (aip);
209 }
210 }
211
212
213 static void DeleteFeatureCallback (SeqFeatPtr sfp, Pointer userdata)
214 {
215 BioseqPtr prot_bsp;
216
217 if (sfp != NULL) {
218 sfp->idx.deleteme = TRUE;
219 if (sfp->data.choice == SEQFEAT_CDREGION) {
220 prot_bsp = BioseqFindFromSeqLoc (sfp->product);
221 if (prot_bsp != NULL) {
222 prot_bsp->idx.deleteme = TRUE;
223 }
224 }
225 }
226 }
227
228
229 static Boolean IsCitSubPub (PubdescPtr pdp)
230 {
231 ValNodePtr vnp;
232 Boolean is_cit_sub = FALSE;
233
234 if (pdp == NULL) return FALSE;
235 for (vnp = pdp->pub; vnp != NULL && !is_cit_sub; vnp = vnp->next) {
236 if (vnp->choice == PUB_Sub) {
237 is_cit_sub = TRUE;
238 }
239 }
240 return is_cit_sub;
241 }
242
243 static void DeleteDescriptorsCallback (SeqDescrPtr sdp, Pointer userdata)
244 {
245 ObjValNodePtr ovp;
246 StripItemsPtr sip;
247
248 if (sdp != NULL
249 && (sip = (StripItemsPtr) userdata) != NULL
250 && sdp->extended != 0) {
251 ovp = (ObjValNodePtr) sdp;
252 if (sdp->choice == Seq_descr_pub) {
253 if (sip->strip_noncitsubpubs && sip->strip_citsubpubs) {
254 /* strip all pubs */
255 ovp->idx.deleteme = TRUE;
256 } else if (sip->strip_citsubpubs && IsCitSubPub ((PubdescPtr)sdp->data.ptrvalue)) {
257 /* strip citsubpub */
258 ovp->idx.deleteme = TRUE;
259 } else if (sip->strip_noncitsubpubs && !IsCitSubPub ((PubdescPtr)sdp->data.ptrvalue)) {
260 /* strip noncitsubpub */
261 ovp->idx.deleteme = TRUE;
262 }
263 } else if (sip->strip_comment_descriptors && sdp->choice == Seq_descr_comment) {
264 /* strip comment descriptors */
265 ovp->idx.deleteme = TRUE;
266 }
267 }
268 }
269
270
271 static Boolean OkToStripSeqEntry (SeqEntryPtr sep)
272 {
273 Boolean rval = TRUE;
274 BioseqSetPtr bssp;
275
276 if (sep == NULL || sep->data.ptrvalue == NULL) {
277 Message (MSG_POSTERR, "Unable to get Seq-entry");
278 rval = FALSE;
279 } else if (IS_Bioseq_set (sep)) {
280 bssp = (BioseqSetPtr) sep->data.ptrvalue;
281 if (bssp->seq_set == NULL) {
282 Message (MSG_POSTERR, "Seq-entry contains no Bioseqs!");
283 rval = FALSE;
284 } else if (bssp->_class != BioseqseqSet_class_nuc_prot
285 || !IS_Bioseq (bssp->seq_set)) {
286 Message (MSG_POSTERR, "Contains a set that is not a nuc-prot set!");
287 rval = FALSE;
288 }
289 }
290 return rval;
291 }
292
293 static Boolean OkToStripTopLevelEntry (SeqEntryPtr sep)
294 {
295 Boolean rval = TRUE;
296 BioseqSetPtr bssp;
297 SeqEntryPtr subsep;
298
299 if (IS_Bioseq_set (sep)) {
300 bssp = (BioseqSetPtr) sep->data.ptrvalue;
301 if (bssp->_class != BioseqseqSet_class_nuc_prot
302 && bssp->_class != BioseqseqSet_class_not_set
303 && bssp->_class != BioseqseqSet_class_genbank) {
304 Message (MSG_POSTERR, "Can only process Bioseqs and Nuc-prot sets.");
305 rval = FALSE;
306 }
307 for (subsep = bssp->seq_set; subsep != NULL && rval; subsep = subsep->next) {
308 if (!OkToStripSeqEntry (subsep)) {
309 rval = FALSE;
310 }
311 }
312 }
313 return rval;
314 }
315
316 static Uint2 ProcessOneAsn (
317 FILE* fp,
318 CharPtr path,
319 StripItemsPtr sip
320 )
321
322 {
323 Pointer dataptr;
324 Uint2 datatype, entityID = 0;
325 SeqEntryPtr sep;
326
327 if (fp == NULL || sip == NULL) return 0;
328
329 dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, &entityID, TRUE, FALSE, TRUE, FALSE);
330 if (dataptr == NULL) {
331 Message (MSG_POSTERR, "Unable to read data from %s.", path);
332 return 0;
333 }
334
335 sep = GetTopSeqEntryForEntityID (entityID);
336 if (!OkToStripTopLevelEntry (sep)) {
337 Message (MSG_POSTERR, "Failed for %s", path);
338 ObjMgrFreeByEntityID (entityID);
339 entityID = 0;
340 } else {
341 if (sip->strip_features) {
342 VisitFeaturesInSep (sep, NULL, DeleteFeatureCallback);
343 }
344 if (sip->strip_noncitsubpubs || sip->strip_citsubpubs || sip->strip_comment_descriptors) {
345 VisitDescriptorsInSep (sep, sip, DeleteDescriptorsCallback);
346 }
347 DeleteMarkedObjects (entityID, 0, NULL);
348 RenormalizeNucProtSets (sep, TRUE);
349 }
350
351 return entityID;
352 }
353
354 /* return -1 if failure, 0 if success */
355 static Int4 ProcessOneRecord (
356 CharPtr directory,
357 OutputStreamPtr osp,
358 StripItemsPtr sip
359 )
360
361 {
362 Uint2 entityID;
363 FILE *fp;
364 SeqEntryPtr sep;
365 SeqSubmitPtr ssp = NULL;
366
367 if (osp == NULL || sip == NULL) return -1;
368 fp = OpenOneFile (directory, osp->base, osp->suffix);
369 if (fp == NULL) return -1;
370
371 entityID = ProcessOneAsn (fp, osp->base == NULL ? "input stream" : osp->base, sip);
372
373 FileClose (fp);
374
375 if (entityID == 0) return -1;
376
377 /* finish processing */
378
379 sep = GetTopSeqEntryForEntityID (entityID);
380 if (sep != NULL) {
381 if (!sip->strip_citsubpubs) {
382 SeqMgrIndexFeatures (entityID, NULL);
383 ssp = FindSeqSubmitForSeqEntry (sep);
384 }
385 if (ssp == NULL) {
386 WriteOneFile (osp, sep);
387 } else {
388 WriteOneSeqSubmitFile (osp, ssp);
389 }
390 }
391
392 ObjMgrFreeByEntityID (entityID);
393 return 0;
394 }
395
396 static Int4 ProcessStream (InputStreamPtr isp, OutputStreamPtr osp, AsnStreamPtr asp, StripItemsPtr sip)
397 {
398 AsnTypePtr atp, atp_srch;
399 AsnIoPtr asn_in, asn_out;
400 Int4 rval = 0;
401 SeqEntryPtr sep;
402 Uint2 entityID;
403 DataVal av;
404
405 if (isp == NULL || osp == NULL || asp == NULL || sip == NULL) return 1;
406
407 asn_in = AsnIoFromInputStream (isp);
408 asn_out = AsnIoFromOutputStream (osp);
409
410 if (isp->is_seqentry) {
411 atp = asp->atp_se;
412 atp_srch = asp->atp_se;
413 }
414 else {
415 atp = asp->atp_bss;
416 atp_srch = asp->atp_bss_se;
417 }
418
419 while ((atp = AsnReadId(asn_in, asp->amp, atp)) != NULL && rval == 0) {
420 if (atp != atp_srch) {
421 AsnReadVal(asn_in, atp, &av);
422 AsnWrite(asn_out, atp, &av);
423 AsnKillValue(atp, &av);
424 continue;
425 }
426 if ((sep = SeqEntryAsnRead(asn_in, atp)) == NULL) {
427 Message (MSG_POSTERR, "SeqEntryAsnRead failure");
428 rval = 1;
429 } else if (!OkToStripTopLevelEntry (sep)) {
430 rval = 1;
431 }
432 if (rval == 0) {
433 entityID = ObjMgrRegister (OBJ_SEQENTRY, sep);
434 if (sip->strip_features) {
435 VisitFeaturesInSep (sep, NULL, DeleteFeatureCallback);
436 }
437 if (sip->strip_noncitsubpubs || sip->strip_citsubpubs || sip->strip_comment_descriptors) {
438 VisitDescriptorsInSep (sep, sip, DeleteDescriptorsCallback);
439 }
440 DeleteMarkedObjects (entityID, 0, NULL);
441 RenormalizeNucProtSets (sep, TRUE);
442 if (! SeqEntryAsnWrite(sep, asn_out, atp)) {
443 Message (MSG_POSTERR, "SeqEntryAsnWrite failure");
444 rval = 1;
445 }
446 AsnIoFlush(asn_out);
447 ObjMgrFreeByEntityID (entityID);
448 }
449 } /* Endwhile, AsnReadId */
450
451 AsnIoClose(asn_in);
452 if (asn_out != osp->aip) {
453 AsnIoClose(asn_out);
454 }
455
456 return rval;
457 }
458
459 /* return -1 on failure, 0 on success */
460 static Int4 FileRecurse (
461 CharPtr directory,
462 InputStreamPtr isp,
463 OutputStreamPtr osp,
464 AsnStreamPtr asp,
465 StripItemsPtr sip
466 )
467
468 {
469 Char path [PATH_MAX];
470 CharPtr ptr;
471 CharPtr str;
472 ValNodePtr head, vnp;
473 CharPtr orig_dir, orig_base;
474 Int4 rval = 0;
475
476 /* get list of all files in source directory */
477
478 head = DirCatalog (directory);
479
480 for (vnp = head; vnp != NULL; vnp = vnp->next) {
481 if (vnp->choice == 0) {
482 str = (CharPtr) vnp->data.ptrvalue;
483 if (StringDoesHaveText (str)) {
484
485 /* does filename have desired substring? */
486
487 ptr = StringStr (str, osp->suffix);
488
489 if (ptr != NULL) {
490
491 /* make sure detected suffix is really at end of filename */
492
493 if (StringCmp (ptr, osp->suffix) == 0) {
494 *ptr = '\0';
495
496 /* process file that has desired suffix (usually .fsa) */
497 osp->base = str;
498 orig_dir = isp->directory;
499 isp->directory = directory;
500 orig_base = isp->base;
501 isp->base = str;
502 if (isp->is_binary) {
503 rval |= ProcessStream (isp, osp, asp, sip);
504 } else {
505 rval |= ProcessOneRecord (directory, osp, sip);
506 }
507 isp->directory = orig_dir;
508 isp->base = orig_base;
509 osp->base = NULL;
510 }
511 }
512 }
513 } else if (vnp->choice == 1) {
514
515 /* recurse into subdirectory */
516
517 StringNCpy_0 (path, directory, sizeof (path));
518 str = (CharPtr) vnp->data.ptrvalue;
519 FileBuildPath (path, str, NULL);
520 rval |= FileRecurse (path, isp, osp, asp, sip);
521 }
522 }
523
524 /* clean up file list */
525
526 ValNodeFreeData (head);
527 return rval;
528 }
529
530 static Boolean SetUpAsnStreamData (AsnStreamPtr asp)
531
532 {
533 if (asp == NULL) return FALSE;
534
535 if (! SeqSetAsnLoad()) {
536 Message (MSG_POSTERR, "Unable to load SeqSet parse tree");
537 return FALSE;
538 }
539 asp->amp = AsnAllModPtr();
540 if (asp->amp == NULL) {
541 Message (MSG_POSTERR, "Unable to obtain ASN.1 module pointer");
542 return FALSE;
543 }
544
545 /* Get pointers to ASN.1 types that must be dealt with in asn_in */
546
547 if ( (asp->atp_bss = AsnFind("Bioseq-set")) == NULL) {
548 Message (MSG_POSTERR, "could not find type Bioseq-set");
549 return FALSE;
550 }
551 if ( (asp->atp_bss_se = AsnFind("Bioseq-set.seq-set.E")) == NULL) {
552 Message (MSG_POSTERR, "AsnFind failure: Bioseq-set.seq-set.E");
553 return FALSE;
554 }
555 if ( (asp->atp_se = AsnFind("Seq-entry")) == NULL) {
556 Message (MSG_POSTERR, "AsnFind failure: Seq-entry");
557 return FALSE;
558 }
559 return TRUE;
560 }
561
562 /* Args structure contains command-line arguments */
563
564 #define p_argInputPath 0
565 #define r_argOutputPath 1
566 #define i_argInputFile 2
567 #define o_argOutputFile 3
568 #define x_argSuffix 4
569 #define s_argOutSuffix 5
570 #define b_argInputBinary 6
571 #define e_argInputSeqEntry 7
572 #define d_argOutputBinary 8
573 #define z_argStripNonCitSubPubs 9
574 #define Z_argStripCitSubPubs 10
575 #define c_argStripCommentDescriptors 11
576
577 Args myargs [] = {
578 {"Path to Files", NULL, NULL, NULL,
579 TRUE, 'p', ARG_STRING, 0.0, 0, NULL},
580 {"Path for Results", NULL, NULL, NULL,
581 TRUE, 'r', ARG_STRING, 0.0, 0, NULL},
582 {"Single Input File", NULL, NULL, NULL,
583 TRUE, 'i', ARG_FILE_IN, 0.0, 0, NULL},
584 {"Single Output File", NULL, NULL, NULL,
585 TRUE, 'o', ARG_FILE_OUT, 0.0, 0, NULL},
586 {"Suffix", ".sqn", NULL, NULL,
587 TRUE, 'x', ARG_STRING, 0.0, 0, NULL},
588 {"Suffix for stripped files", "", NULL, NULL,
589 TRUE, 's', ARG_STRING, 0.0, 0, NULL},
590 {"Input is binary", "F", NULL, NULL,
591 TRUE, 'b', ARG_BOOLEAN, 0.0, 0, NULL},
592 {"Input is Seq-entry", "F", NULL, NULL,
593 TRUE, 'e', ARG_BOOLEAN, 0.0, 0, NULL},
594 {"Output is binary", "F", NULL, NULL,
595 TRUE, 'b', ARG_BOOLEAN, 0.0, 0, NULL},
596 {"Strip non-CitSub Pubs", "F", NULL, NULL,
597 TRUE, 'z', ARG_BOOLEAN, 0.0, 0, NULL},
598 {"Strip CitSub Pubs", "F", NULL, NULL,
599 TRUE, 'Z', ARG_BOOLEAN, 0.0, 0, NULL},
600 {"Strip Comment Descriptors", "F", NULL, NULL,
601 TRUE, 'c', ARG_BOOLEAN, 0.0, 0, NULL}
602 };
603
604 Int2 Main(void)
605 {
606 Char app [64];
607 CharPtr directory;
608 CharPtr ptr;
609 Char sfx [32];
610 OutputStreamData osd;
611 InputStreamData isd;
612 AsnStreamData asd;
613 StripItemsData sid;
614 Int4 rval = 0;
615
616 /* standard setup */
617
618 ErrSetFatalLevel (SEV_MAX);
619 ErrClearOptFlags (EO_SHOW_USERSTR);
620 UseLocalAsnloadDataAndErrMsg ();
621 ErrPathReset ();
622
623 /* finish resolving internal connections in ASN.1 parse tables */
624
625 if (! AllObjLoad ()) {
626 Message (MSG_FATAL, "AllObjLoad failed");
627 return 1;
628 }
629 if (! SubmitAsnLoad ()) {
630 Message (MSG_FATAL, "SubmitAsnLoad failed");
631 return 1;
632 }
633 if (! FeatDefSetLoad ()) {
634 Message (MSG_FATAL, "FeatDefSetLoad failed");
635 return 1;
636 }
637 if (! SeqCodeSetLoad ()) {
638 Message (MSG_FATAL, "SeqCodeSetLoad failed");
639 return 1;
640 }
641 if (! GeneticCodeTableLoad ()) {
642 Message (MSG_FATAL, "GeneticCodeTableLoad failed");
643 return 1;
644 }
645
646 SetUpAsnStreamData (&asd);
647
648 /* initialize OuputStreamData */
649 MemSet (&osd, 0, sizeof (osd));
650
651 /* initialize InputStreamData */
652 MemSet (&isd, 0, sizeof (isd));
653
654 /* initialize StripItemsData */
655 MemSet (&sid, 0, sizeof (sid));
656
657 /* process command line arguments */
658
659 sprintf (app, "asnstrip %s", ASNSTRIP_APPLICATION);
660 if (! GetArgs (app, sizeof (myargs) / sizeof (Args), myargs)) {
661 return 0;
662 }
663
664 /* collect items to be stripped */
665 sid.strip_citsubpubs = (Boolean) myargs [Z_argStripCitSubPubs].intvalue;
666 sid.strip_noncitsubpubs = (Boolean) myargs [z_argStripNonCitSubPubs].intvalue;
667 sid.strip_features = TRUE; /* by default, for now */
668 sid.strip_comment_descriptors = (Boolean) myargs [c_argStripCommentDescriptors].intvalue;
669
670 directory = (CharPtr) myargs [p_argInputPath].strvalue;
671 osd.results_dir = (CharPtr) myargs [r_argOutputPath].strvalue;
672 if (StringHasNoText (osd.results_dir)) {
673 osd.results_dir = NULL;
674 }
675 osd.suffix = (CharPtr) myargs [x_argSuffix].strvalue;
676 osd.outsuffix = (CharPtr) myargs [s_argOutSuffix].strvalue;
677 osd.base = (CharPtr) myargs [i_argInputFile].strvalue;
678 osd.outfile = (CharPtr) myargs [o_argOutputFile].strvalue;
679 if (StringHasNoText (osd.outfile)) {
680 osd.outfile = NULL;
681 }
682 osd.is_binary = (Boolean) myargs [d_argOutputBinary].intvalue;
683
684 if (osd.base == "stdin") {
685 osd.base = NULL;
686 }
687
688 /* if we don't have an output directory or an output file, and the user hasn't provided an
689 * output suffix, add a default.
690 */
691 if (osd.results_dir == NULL && osd.outfile == NULL && StringHasNoText (osd.outsuffix)) {
692 osd.outsuffix = ".stripped";
693 }
694
695 isd.is_binary = (Boolean) myargs [b_argInputBinary].intvalue;
696 isd.is_seqentry = (Boolean) myargs [e_argInputSeqEntry].intvalue;
697 isd.directory = directory;
698 isd.base = osd.base;
699 isd.suffix = osd.suffix;
700
701 if (StringDoesHaveText (osd.outfile)) {
702 osd.aip = AsnIoOpen (osd.outfile, "w");
703 if (osd.aip == NULL) {
704 Message (MSG_FATAL, "Unable to open output file");
705 return 1;
706 }
707 } else {
708 if (StringHasNoText (osd.results_dir)) {
709 osd.results_dir = directory;
710 }
711 /* if we're putting the results in a separate directory, strip the directory name from the output base */
712 if (!StringHasNoText (osd.results_dir) && !StringHasNoText (osd.base)) {
713 #ifdef OS_MSWIN
714 ptr = StringRChr (osd.base, '\\');
715 #else
716 ptr = StringRChr (osd.base, '/');
717 #endif;
718 if (ptr != NULL) {
719 osd.base = ptr + 1;
720 }
721 }
722 }
723
724
725 if (StringHasNoText(directory) && StringHasNoText(osd.base)) {
726 rval = ProcessStream (&isd, &osd, &asd, &sid);
727 } else if (StringDoesHaveText (osd.base)) {
728 ptr = StringRChr (osd.base, '.');
729 sfx[0] = '\0';
730 if (ptr != NULL) {
731 StringNCpy_0 (sfx, ptr, sizeof (sfx));
732 *ptr = '\0';
733 }
734 osd.suffix = sfx;
735 isd.suffix = sfx;
736 if (isd.is_binary) {
737 rval = ProcessStream (&isd, &osd, &asd, &sid);
738 } else {
739 rval = ProcessOneRecord (directory, &osd, &sid);
740 }
741 } else {
742
743 rval = FileRecurse (directory, &isd, &osd, &asd, &sid);
744 }
745
746 if (osd.aip != NULL) {
747 AsnIoFlush (osd.aip);
748 AsnIoClose (osd.aip);
749 }
750 return rval;
751 }
752 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |