예제 #1
0
파일: testmem.c 프로젝트: hsptools/hsp-wrap
Int2 Main(void)
{
	AsnIoPtr aip;
	SeqEntryPtr sep;
	BytePtr buf;
	Uint2 size = 32000, count;
	AsnIoMemPtr aimp;

					/* check command line arguments */

	if ( ! GetArgs("testmem",NUMARG, myargs))
		return 1;

					/* load the sequence alphabets  */
					/* (and sequence parse trees)   */
	if (! SeqEntryLoad())
		ErrShow();

					/* open the ASN.1 input file in the right mode */

	if ((aip = AsnIoOpen (myargs[0].strvalue, myargs[1].intvalue?"rb":"r"))
          == NULL)
		ErrShow();
	sep = SeqEntryAsnRead(aip, NULL);   	/* read the entry */
	AsnIoClose(aip);

	SeqEntryPack(sep);						/* pack it */

	buf = MemNew(size);                     /* allocate a buffer */
	aimp = AsnIoMemOpen("wb", buf, size);	/* open to write asn1 to it */
	SeqEntryAsnWrite(sep, aimp->aip, NULL);	/* write it */
	AsnIoFlush(aimp->aip);					/* flush it */
	count = aimp->count;					/* record how many bytes in it */
	AsnIoMemClose(aimp);					/* close it */

	SeqEntryFree(sep);						/* release the object */

	aimp = AsnIoMemOpen("rb", buf, count);	/* open to read from buffer */
	sep = SeqEntryAsnRead(aimp->aip, NULL);	/* read it */
	AsnIoMemClose(aimp);					/* close it */
	MemFree(buf);							/* free the buffer */

				  				/* open the output file */

	aip = AsnIoOpen (myargs[2].strvalue, "w");
	SeqEntryAsnWrite(sep, aip, NULL);	/* print it */
	AsnIoClose(aip);

	SeqEntryFree(sep);

	return(0);
}
예제 #2
0
static Boolean LoadObjPrtFromLocalString (CharPtr localStr)

{
  Boolean     retval = FALSE;
#ifndef WIN16
  AsnIoMemPtr aimp;

  aimp = AsnIoMemOpen ("r", (BytePtr) localStr, (Int4) StringLen (localStr));
  if (aimp == NULL || aimp->aip == NULL) return FALSE;
  retval = PrintTemplateSetAsnRead (aimp->aip);
  AsnIoMemClose (aimp);
#endif
  return retval;
}
예제 #3
0
static void s_TestIdFormatting(const char* s)
{
    size_t            len = strlen(s);
    CObjectIStreamAsn ois(s, len);
    CSeq_id           cxx_id;
    AsnIoMemPtr       aimp = AsnIoMemOpen
        (const_cast<char*>("r"),
         reinterpret_cast<BytePtr>(const_cast<char*>(s)), len);
    AsnIoPtr          aip = AsnIoNew((ASNIO_IN | ASNIO_TEXT), NULL, aimp,
                                     AsnIoMemRead, AsnIoMemWrite);
    TAutoSeqId        c_id;

    ois.Read(&cxx_id, CSeq_id::GetTypeInfo(), CObjectIStream::eNoFileHeader);
    aip->read_id = TRUE;
    c_id = SeqIdAsnRead(aip, s_SeqIdATP);

    BOOST_CHECK_EQUAL(s_IdLabel(c_id,   eFastaShort),
                      s_IdLabel(cxx_id, eFastaShort));
    BOOST_CHECK_EQUAL(s_IdLabel(c_id,   eTextAccVer),
                      s_IdLabel(cxx_id, eTextAccVer));
    BOOST_CHECK_EQUAL(s_IdLabel(c_id,   eTextAccOnly),
                      s_IdLabel(cxx_id, eTextAccOnly));
    BOOST_CHECK_EQUAL(s_IdLabel(c_id, eReport), s_IdLabel(cxx_id, eReport));
}