1 /*****************************************************************************
2 *
3 *   makeset.c
4 *      build a Bioseq-set from a bunch of Seq-entry files
5 *      expects a file of file names in stdin
6 *      prints the Bioseq-set out stdout in binary
7 *
8 *****************************************************************************/
9 #include <all.h>
10 
11 #define NUMARGS 6
12 Args myargs[NUMARGS] = {
13 	{ "Input File Names", "stdin", NULL, NULL, FALSE, 'i', ARG_FILE_IN, 0.0,0,NULL},
14 	{ "Input data is binary", "F", NULL, NULL, TRUE , 'd', ARG_BOOLEAN, 0.0,0,NULL},
15 	{ "Output data as binary", "T", NULL, NULL, TRUE , 'b', ARG_BOOLEAN, 0.0,0,NULL},
16 	{ "Output Bioseq-set", "stdout", "Bioseq-set", NULL, FALSE, 'o', ARG_DATA_OUT, 0.0,0,NULL},
17 	{ "Bioseq-set.class", "255", NULL, NULL, FALSE , 'c', ARG_INT, 0.0,0,NULL},
18 	{ "Bioseq-set.release", NULL, NULL, NULL, TRUE , 'r', ARG_STRING, 0.0,0,NULL}};
19 
20 
21 
Main(void)22 Int2 Main(void)
23 {
24 	AsnIoPtr aipin, aip;
25 	AsnTypePtr atp;
26 	DataVal value;
27 	Int4 seekptr, tempseek, uid;
28 	static CharPtr outtypes[2] = { "w", "wb" };
29 	static CharPtr intypes[2] = { "r", "rb" };
30 	Int2 outtype, intype;
31 	FILE *fp;
32 	Char fname[80];
33 	CharPtr tmp;
34 
35     if (! AsnLoad())
36         Message(MSG_FATAL, "Unable to load all parse tree.");
37 
38 	if (! GetArgs("MakeSet 1.0", NUMARGS, myargs))
39 		return 1;
40 
41 	if (myargs[1].intvalue)        /* binary input is TRUE */
42 		intype = 1;
43 	else
44 		intype = 0;
45 
46 	if (myargs[2].intvalue)        /* binary output is TRUE */
47 		outtype = 1;
48 	else
49 		outtype = 0;
50 
51 	if ((aip = AsnIoOpen(myargs[3].strvalue, outtypes[outtype])) == NULL)
52 	{
53 		Message(MSG_ERROR, "Couldn't open %s for output", myargs[3].strvalue);
54 		return 1;
55 	}
56 
57 	if ((fp = FileOpen(myargs[0].strvalue, "r")) == NULL)
58 	{
59 		Message(MSG_ERROR, "Couldn't open %s for input", myargs[0].strvalue);
60 		return 1;
61 	}
62 
63 	AsnOpenStruct(aip, BIOSEQ_SET, NULL);
64 	value.intvalue = myargs[4].intvalue;
65 	AsnWrite(aip, BIOSEQ_SET_class, &value);
66 	if (myargs[5].strvalue != NULL)
67 	{
68 		value.ptrvalue = myargs[5].strvalue;
69 		AsnWrite(aip, BIOSEQ_SET_release, &value);
70 	}
71 	AsnOpenStruct(aip, BIOSEQ_SET_seq_set, NULL);
72 
73 	while (FileGets(fname, (size_t)78, fp) != NULL)
74 	{
75 		tmp = fname;
76 		if (*tmp <= ' ') break;
77 		while (*tmp >= ' ') tmp++;
78 		*tmp = '\0';
79 		aipin = AsnIoOpen(fname, intypes[intype]);
80 		if (aipin == NULL)
81 		{
82 			Message(MSG_ERROR, "Couldn't open %s for input", fname);
83 			return 1;
84 		}
85 		atp = SEQ_ENTRY;
86 		atp = AsnReadId(aipin, amp, atp);
87 		AsnReadVal(aipin, atp, &value);
88 		AsnWrite(aip, BIOSEQ_SET_seq_set_E, &value);
89 		while (AsnGetLevel(aipin) > 0)
90 		{
91 			atp = AsnReadId(aipin, amp, atp);
92 			AsnReadVal(aipin, atp, &value);
93 			AsnWrite(aip, atp, &value);
94 			AsnKillValue(atp, &value);
95 		}
96 		aipin = AsnIoClose(aipin);
97 	}
98 	AsnCloseStruct(aip, BIOSEQ_SET_seq_set, NULL);
99 	AsnCloseStruct(aip, BIOSEQ_SET, NULL);
100 	aip = AsnIoClose(aip);
101 	FileClose(fp);
102 	return 0;
103 }
104 
105 
106