1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
/*****************************************************************************
*
* $Id: asn2xml.c,v 1.2 2001/08/10 18:56:42 kans Exp $
*
* asn2xml.c
*
* This program is based on asn2asn.c but modified specifically to
* efficiently convert asn.1 Seq-entry or Bioseq-set into XML. The
* only real difference with asn2asn -x is that a special step puts
* the Seq-inst through the object loaders to convert 2 bit and 4 bit
* encodings to text formats (1 base per letter) that XML fans prefer.
*
* The defaults are set so that you can pipe the binary asn.1 Bioseq-set
* in the GenBank release or update.
*
* cat update.ent | asn2xml | myxmlreader
*
* Author: Jim Ostell <ostell@ncbi.nlm.nih.gov>
*
*****************************************************************************/
#include <seqport.h>
#include <objsub.h>
#define NUMARG 6
Args myargs[NUMARG] = {
{"Filename for asn.1 input","stdin",NULL,NULL,FALSE,'i',ARG_FILE_IN,0.0,0,NULL},
{"Input is a Seq-entry","F", NULL ,NULL ,TRUE,'e',ARG_BOOLEAN,0.0,0,NULL},
{"Input is a Seq-submit","F", NULL ,NULL ,TRUE,'s',ARG_BOOLEAN,0.0,0,NULL},
{"Input asnfile in binary mode","T",NULL,NULL,TRUE,'b',ARG_BOOLEAN,0.0,0,NULL},
{"Filename for XML output","stdout", NULL,NULL,TRUE,'o',ARG_FILE_OUT,0.0,0,NULL},
{"Log errors to file named:",NULL,NULL,NULL,TRUE,'l',ARG_FILE_OUT, 0.0,0,NULL}};
/*****************************************************************************
*
* Main program loop to read, process, write SeqEntrys
*
*****************************************************************************/
Int2 Main(void)
{
AsnIoPtr aipout=NULL, aipin;
AsnTypePtr atp, atp_inst;
AsnModulePtr amp;
DataVal dv;
CharPtr ftype;
BioseqPtr bsp;
/* check command line arguments */
if ( ! GetArgs("asn2xml 1.0",NUMARG, myargs))
return 1;
/* load the sequence alphabets */
/* (and sequence parse trees) */
if (! SeqEntryLoad())
ErrShow();
if (! SubmitAsnLoad())
ErrShow();
if (! SeqCodeSetLoad())
ErrShow();
/* get pointer to all loaded ASN.1 modules */
amp = AsnAllModPtr();
if (amp == NULL)
{
ErrShow();
return 1;
}
if (myargs[1].intvalue)
atp = AsnFind("Seq-entry");
else if (myargs[2].intvalue)
atp = AsnFind("Seq-submit");
else
atp = AsnFind("Bioseq-set"); /* get the initial type pointers */
if (atp == NULL)
{
ErrShow();
return 1;
}
atp_inst = AsnFind("Bioseq.inst");
if (atp_inst == NULL)
{
ErrShow();
return 1;
}
/* open the ASN.1 input file in the right mode */
if ((aipin = AsnIoOpen (myargs[0].strvalue, myargs[3].intvalue?"rb":"r"))
== NULL)
{
ErrPostEx(SEV_ERROR,0,0, "Can't open %s", myargs[0].strvalue);
ErrShow();
return 1;
}
/* open the ASN.1 output file in the right mode */
if (myargs[4].strvalue != NULL) /* output desired? */
{
ftype = "wx";
if ((aipout = AsnIoOpen (myargs[4].strvalue, ftype)) == NULL)
{
ErrPostEx(SEV_ERROR,0,0, "Can't open %s", myargs[4].strvalue);
ErrShow();
return 1;
}
}
/* log errors instead of die */
if (myargs[5].strvalue != NULL)
{
if (! ErrSetLog (myargs[5].strvalue))
{
ErrShow();
return 1;
}
else
ErrSetOpts (ERR_CONTINUE, ERR_LOG_ON);
}
while ((atp = AsnReadId(aipin, amp, atp)) != NULL)
{
if (atp == atp_inst) /* need object loader convert */
{
bsp = BioseqNew(); /* need newly initialized bsp */
BioseqInstAsnRead(bsp, aipin, atp);
BioseqInstAsnWrite(bsp, aipout, atp);
bsp = BioseqFree(bsp);
}
else
{
AsnReadVal(aipin, atp, &dv); /* read it */
AsnWrite(aipout, atp, &dv); /* write it */
AsnKillValue(atp, &dv); /* free it */
}
}
AsnIoClose(aipin);
AsnIoClose(aipout);
return(0);
}
|