Exemplo n.º 1
0
static Boolean SetUpAsnStreamData (AsnStreamPtr asp)

{
  if (asp == NULL) return FALSE;

  if (! SeqSetAsnLoad()) {
    Message (MSG_POSTERR, "Unable to load SeqSet parse tree");
    return FALSE;
  }
  asp->amp = AsnAllModPtr();
  if (asp->amp == NULL) {
    Message (MSG_POSTERR, "Unable to obtain ASN.1 module pointer");
    return FALSE;
  }

  /* Get pointers to ASN.1 types that must be dealt with in asn_in */

  if ( (asp->atp_bss = AsnFind("Bioseq-set")) == NULL) {
    Message (MSG_POSTERR, "could not find type Bioseq-set");
    return FALSE;
  }
  if ( (asp->atp_bss_se = AsnFind("Bioseq-set.seq-set.E")) == NULL) {
    Message (MSG_POSTERR, "AsnFind failure: Bioseq-set.seq-set.E");
    return FALSE;
  }
  if ( (asp->atp_se = AsnFind("Seq-entry")) == NULL) {
    Message (MSG_POSTERR, "AsnFind failure: Seq-entry");
    return FALSE;
  }
  return TRUE;
}
Exemplo n.º 2
0
/*****************************************************************************
*
*   AllAsnLoad()
*
*****************************************************************************/
NLM_EXTERN Boolean AllAsnLoad (void)

{
    static Boolean loaded = FALSE;
    AsnModulePtr  amp;
    AsnTypePtr    atp;

    if (loaded)
        return TRUE;
    loaded = TRUE;

    if (! AsnLoad()) {
        loaded = FALSE;
        return FALSE;
    }

    amp = AsnAllModPtr ();
    atp = AsnTypeFind (amp, "Bioseq");

    ObjMgrTypeLoad(OBJ_FASTA, "Bioseq", simplename, "Simple Sequence",
        atp, SimpleSeqNewFunc, SimpleSeqAsnReadFunc, NULL,
        SimpleSeqFreeFunc, NULL, NULL);

    return TRUE;
}
Exemplo n.º 3
0
/*****************************************************************************
*
*   AllObjLoad()
*
*****************************************************************************/
NLM_EXTERN AsnModulePtr LIBCALL AllObjLoad (void)
{
    if (SeqSetAsnLoad())     /* load the most complicated object loader */
        return AsnAllModPtr();
    else
        return NULL;
}
Exemplo n.º 4
0
/*****************************************************************************
*
*   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);
}
Exemplo n.º 5
0
Int2 Main (void)

{
  AsnIoPtr      aop = NULL;
  AsnModulePtr  amp;
  AsnTypePtr    atp_bss, atp_ss, atp_se;
  BioseqSet     bss;
  FILE          *fp;
  ValNodePtr    head, vnp;
  Char          path [PATH_MAX];
  CharPtr       progname, str, subfile;

  ErrSetFatalLevel (SEV_MAX);
  ErrClearOptFlags (EO_SHOW_USERSTR);
  UseLocalAsnloadDataAndErrMsg ();
  ErrPathReset ();

  if (! AllObjLoad ()) {
    Message (MSG_FATAL, "AllObjLoad failed");
    return 1;
  }
  if (! SubmitAsnLoad ()) {
    Message (MSG_FATAL, "SubmitAsnLoad failed");
    return 1;
  }
  if (! SeqCodeSetLoad ()) {
    Message (MSG_FATAL, "SeqCodeSetLoad failed");
    return 1;
  }
  if (! GeneticCodeTableLoad ()) {
    Message (MSG_FATAL, "GeneticCodeTableLoad failed");
    return 1;
  }

  MemSet ((Pointer) &bss, 0, sizeof (BioseqSet));

  amp = AsnAllModPtr ();
  if (amp == NULL) {
    Message (MSG_FATAL, "Unable to load AsnAllModPtr");
    return 1;
  }

  atp_bss = AsnFind ("Bioseq-set");
  if (atp_bss == NULL) {
    Message (MSG_FATAL, "Unable to find ASN.1 type Bioseq-set");
    return 1;
  }

  atp_ss = AsnFind ("Bioseq-set.seq-set");
  if (atp_ss == NULL) {
    Message (MSG_FATAL, "Unable to find ASN.1 type Bioseq-set.seq-set");
    return 1;
  }


  atp_se = AsnFind ("Bioseq-set.seq-set.E");
  if (atp_se == NULL) {
    Message (MSG_FATAL, "Unable to find ASN.1 type Bioseq-set.seq-set.E");
    return 1;
  }

  ProgramPath (path, sizeof (path));
  progname = StringRChr (path, DIRDELIMCHR);
  if (progname != NULL) {
    progname++;
  } else {
    progname = "idcleanscan";
  }

  if (! GetArgs (progname, sizeof (myargs) / sizeof (Args), myargs)) {
    return 0;
  }

  fp = FileOpen (myargs [o_argOutputFile].strvalue, "a");
  if (fp == NULL) {
    Message (MSG_FATAL, "FileOpen failed");
    return 1;
  }

  if (StringHasNoText (myargs [p_argInputPath].strvalue)) {

    str = myargs [i_argInputFile].strvalue;
    if (! StringHasNoText (str)) {
      DoReleaseFile (str, myargs [b_argBinaryFile].intvalue, myargs [c_argCompressed].intvalue, fp, aop, NULL);
    }

  } else {

    head = DirCatalog (myargs [p_argInputPath].strvalue);

    if (! StringHasNoText (myargs [s_argSubset].strvalue)) {
      aop = AsnIoOpen (myargs [s_argSubset].strvalue, /* "wb" */ "w");
      AsnOpenStruct (aop, atp_bss, (Pointer) &bss);
      AsnOpenStruct (aop, atp_ss, (Pointer) bss.seq_set);
      /*
      av.intvalue = BioseqseqSet_class_genbank;
      AsnWrite (aop, atp_cls, &av);
      */
    }

    for (vnp = head; vnp != NULL; vnp = vnp->next) {
      if (vnp->choice == 0) {
        str = (CharPtr) vnp->data.ptrvalue;
        if (! StringHasNoText (str)) {
          subfile = myargs [x_argFileSelect].strvalue;
          if (StringHasNoText (subfile) || StringStr (str, subfile) != NULL) {
#ifdef OS_UNIX
            /* printf ("%s\n", str); */
#endif
            DoReleaseFile (str, myargs [b_argBinaryFile].intvalue, myargs [c_argCompressed].intvalue, fp, aop, atp_se);
          }
        }
      }
    }

    if (aop != NULL) {
      AsnCloseStruct (aop, atp_ss, (Pointer) bss.seq_set);
      AsnCloseStruct (aop, atp_bss, (Pointer) &bss);
      AsnIoClose (aop);
    }

    ValNodeFreeData (head);
  }

  FileClose (fp);

  return 0;
}
Exemplo n.º 6
0
Int2 Main(void)
{
	AsnIoPtr aip;
	FILE * aa = NULL, * na = NULL, * ql = NULL;
	SeqEntryPtr sep;
	SeqSubmitPtr ssp;
	AsnTypePtr atp, atp2;
	AsnModulePtr amp;
	Uint1 group_segs = 0;
	Boolean limit_to_genbank,
		make_dna,
		make_protein,
		make_quality,
		far_quality,
		do_it;
	

					/* check command line arguments */

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

					/* load the sequence alphabets  */
					/* (and sequence parse trees)   */
	if (! SeqEntryLoad())
	{
		ErrShow();
		return 1;
	}
				    /* get pointer to all loaded ASN.1 modules */
	amp = AsnAllModPtr();
	if (amp == NULL)
	{
		ErrShow();
		return 1;
	}

	if (myargs[11].intvalue) {
		if (! SubmitAsnLoad())
			Message(MSG_FATAL, "Unable to load parse trees.");
		
		atp2 = AsnFind("Seq-submit");
		if (atp2 == NULL)
			Message(MSG_FATAL, "Unable to find Seq-submit");
		atp = AsnFind("Seq-submit");
		if (atp == NULL)
			Message(MSG_FATAL, "Unable to find Seq-submit");

	} else {
		atp = AsnFind("Bioseq-set"); /* get the initial type pointers */
		if (atp == NULL)
		{
			ErrShow();
			return 1;
		}
	
		atp2 = AsnFind("Bioseq-set.seq-set.E");
		if (atp2 == NULL)
		{
			ErrShow();
			return 1;
		}
	}

	make_protein = (Boolean)(myargs[7].intvalue);
	make_dna = (Boolean)(myargs[8].intvalue);
	make_quality = (Boolean)(myargs[12].intvalue);
	far_quality = (Boolean)(myargs[14].intvalue);

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

	if ((aip = AsnIoOpen (myargs[0].strvalue, myargs[2].intvalue?"rb":"r"))
          == NULL)
	{
		ErrShow();
		return 1;
	}

				  				/* open the output file */

	if ((myargs[3].strvalue != NULL) && (make_protein))
	{
		if ( (aa = FileOpen (myargs[3].strvalue, "w")) == NULL)
		{
			ErrShow();
			return 1;
		}
	}

	if ((myargs[4].strvalue != NULL) && (make_dna))
	{
		if ( (na = FileOpen (myargs[4].strvalue, "w")) == NULL)
		{
			ErrShow();
			return 1;
		}
	}

	if ((myargs[13].strvalue != NULL) && (make_quality))
	{
		if ( (ql = FileOpen (myargs[13].strvalue, "w")) == NULL)
		{
			ErrShow();
			return 1;
		}
	}

                                /* log errors instead of die */
    if (myargs[5].strvalue != NULL)
    {
        if (! ErrSetLog (myargs[5].strvalue))
            ErrShow();
        else
            ErrSetOpts (ERR_CONTINUE, ERR_LOG_ON);
   }

	if (myargs[6].intvalue)  /* combine segmented seqs */
	{
		group_segs = 1;
		if (myargs[10].intvalue)
			group_segs = 3;       /* and instantiate virtuals */
	}

	limit_to_genbank = (Boolean)(myargs[9].intvalue);

	if (myargs [15].intvalue) {
		ID1BioseqFetchEnable ("asn2fast", FALSE);
	}
	if (myargs [16].intvalue) {
		LocalSeqFetchInit (FALSE);
	}

	if ( myargs[1].intvalue)   /* read one Seq-entry */
	{

		sep = SeqEntryAsnRead(aip, NULL);
		do_it = TRUE;
		if (limit_to_genbank)
			do_it = CheckIsGenBank(sep);
		if (do_it)
		{
			if (make_protein)
				SeqEntrysToFasta(sep, aa, FALSE, group_segs);
			if (make_dna)
				SeqEntrysToFasta(sep, na, TRUE, group_segs);
			if (make_quality) {
				if (far_quality) {
					SeqEntryExplore (sep, (Pointer) ql, PrintFarQualScores);
				} else {
					SeqEntryExplore (sep, (Pointer) ql, PrintQualScores);
				}
			}
		}
		SeqEntryFree(sep);
	}
	else if ( myargs[11].intvalue)   /* read Seq-submit's */
	{
		while ((atp = AsnReadId(aip, amp, atp)) != NULL)
		{
			if (atp == atp2)    /* top level Seq-entry */
			{
				ssp = SeqSubmitAsnRead(aip, atp);
				if (ssp->datatype == 1)
				{
					sep = (SeqEntryPtr) ssp->data;
					do_it = TRUE;
					if (limit_to_genbank)
						do_it = CheckIsGenBank(sep);
					if (do_it)
					{
						if (make_protein)
							SeqEntrysToFasta(sep, aa, FALSE, group_segs);
						if (make_dna)
							SeqEntrysToFasta(sep, na, TRUE, group_segs);
						if (make_quality) {
							if (far_quality) {
								SeqEntryExplore (sep, (Pointer) ql, PrintFarQualScores);
							} else {
								SeqEntryExplore (sep, (Pointer) ql, PrintQualScores);
							}
						}
					}
				}
				SeqSubmitFree(ssp);
			}
			else
			{
				AsnReadVal(aip, atp, NULL);
			}
		}
	}
	else                      /* read Seq-entry's from a Bioseq-set */
	{
		while ((atp = AsnReadId(aip, amp, atp)) != NULL)
		{
			if (atp == atp2)    /* top level Seq-entry */
			{
				sep = SeqEntryAsnRead(aip, atp);
				do_it = TRUE;
				if (limit_to_genbank)
					do_it = CheckIsGenBank(sep);
				if (do_it)
				{
					if (make_protein)
						SeqEntrysToFasta(sep, aa, FALSE, group_segs);
					if (make_dna)
						SeqEntrysToFasta(sep, na, TRUE, group_segs);
					if (make_quality) {
						if (far_quality) {
							SeqEntryExplore (sep, (Pointer) ql, PrintFarQualScores);
						} else {
							SeqEntryExplore (sep, (Pointer) ql, PrintQualScores);
						}
					}
				}
				SeqEntryFree(sep);
			}
			else
			{
				AsnReadVal(aip, atp, NULL);
			}
		}
	}

	AsnIoClose(aip);
	if (make_protein)
		FileClose(aa);
	if (make_dna)
		FileClose(na);
	if (make_quality)
		FileClose (ql);

	if (myargs [16].intvalue) {
		LocalSeqFetchDisable ();
	}
	if (myargs [15].intvalue) {
		ID1BioseqFetchDisable ();
	}

	return(0);
}
Exemplo n.º 7
0
BGenBankPtr BGenBankInit(void)
{
    BGenBankPtr bgbp;
    AsnModulePtr amp;

    AsnTypePtr       atp_bioseq_set;
    AsnTypePtr       atp_bioseq_set_level;
    AsnTypePtr       atp_bioseq_set_class;
    AsnTypePtr       atp_bioseq_set_release;
    AsnTypePtr       atp_bioseq_set_date;
    AsnTypePtr       atp_bioseq_set_seq_set;
    AsnTypePtr       atp_bioseq_set_seq_set_E;

    Char  release[] = "Q-server Production";
    Char  date_time[128];
    NCBI_Date       date;
    DataVal dv;

    DateClean(&date);

    bgbp = (BGenBankPtr)MemNew(sizeof(BGenBank));
    bgbp->aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);
    
    amp = AsnAllModPtr();

    MACRO_atp_find(atp_bioseq_set,Bioseq-set);
    MACRO_atp_find(atp_bioseq_set_level,Bioseq-set.level);
    MACRO_atp_find(atp_bioseq_set_class,Bioseq-set.class);
    MACRO_atp_find(atp_bioseq_set_release,Bioseq-set.release);
    MACRO_atp_find(atp_bioseq_set_date,Bioseq-set.date);
    MACRO_atp_find(atp_bioseq_set_seq_set,Bioseq-set.seq-set);
    MACRO_atp_find(atp_bioseq_set_seq_set_E,Bioseq-set.seq-set.E);

    if(!AsnOpenStruct(bgbp->aip,atp_bioseq_set,NULL))     
        return NULL;
    dv.intvalue = 0;

    if(!AsnWrite(bgbp->aip,atp_bioseq_set_level,&dv))     
        return NULL;
    dv.intvalue = 7;

    if(!AsnWrite(bgbp->aip,atp_bioseq_set_class,&dv))     
        return NULL;
    dv.ptrvalue = &release;

    if(!AsnWrite(bgbp->aip,atp_bioseq_set_release,&dv))     
        return NULL;

    Nlm_DayTimeStr(date_time,TRUE,TRUE);
    date.str=date_time;

    if(!DateAsnWrite(&date,bgbp->aip,atp_bioseq_set_date))        
        return NULL;
    
    if(!AsnOpenStruct(bgbp->aip,atp_bioseq_set_seq_set,NULL))     
        return NULL;
    AsnIoFlush(bgbp->aip);
    
    bgbp->atp =atp_bioseq_set_seq_set_E;
    bgbp->atp_bioseq_set_seq_set = atp_bioseq_set_seq_set;
    bgbp->atp_bioseq_set = atp_bioseq_set;
    
    return bgbp;
}
Exemplo n.º 8
0
char *readASNSeq(const short whichEntry, const char *filename,
                const long skiplines,
                const short format,     /* note: this is kASNseqentry or kASNseqset */
                long *seqlen, short *nseq,
                short *error, char **seqid )
{
  AsnIoPtr aip = NULL;
  SeqEntryPtr the_set;
  AsnTypePtr atp, atp2;
  AsnModulePtr amp;
  Boolean inIsBinary= FALSE; /* damn, why can't asn routines test this? */
  char  *seq, stemp[200];
  int   i, count;

  *seqlen= 0;
  *nseq= 0;
  *error= 0;
  seq= NULL;

/*fprintf(stderr,"readASNseq: SeqEntryLoad\n");*/
    /* asn dictionary setups */
  if (! SeqEntryLoad()) goto errxit; /*  sequence alphabets (and sequence parse trees) */
  amp = AsnAllModPtr();   /* get pointer to all loaded ASN.1 modules */
  if (amp == NULL) goto errxit;
  atp = AsnFind("Bioseq-set");    /* get the initial type pointers */
  if (atp == NULL) goto errxit;
  atp2 = AsnFind("Bioseq-set.seq-set.E");
  if (atp2 == NULL) goto errxit;

      /* open the ASN.1 input file in the right mode */
/*fprintf(stderr,"readASNseq: AsnIoOpen(%s)\n", filename);*/
  if ((aip = AsnIoOpen(filename, inIsBinary?"rb":"r")) == NULL) goto errxit;
  for (i=0; i<skiplines; i++) fgets( stemp, 255, aip->fp);  /* this may mess up asn routines... */

  if (! ErrSetLog ("stderr"))  goto errxit;
  else ErrSetOpts(ERR_CONTINUE, ERR_LOG_ON);    /*??  log errors instead of die */

  seq= NULL;
  if (format == kASNseqentry) {  /* read one Seq-entry */
/*fprintf(stderr,"readASNseq: SeqEntryAsnRead\n");*/
    the_set = SeqEntryAsnRead(aip, NULL);
    SeqEntryToRaw(the_set, false, whichEntry, nseq, &seq, seqid, seqlen);
    SeqEntryFree(the_set);
    goto goodexit;
    }

  else   {                   /* read Seq-entry's from a Bioseq-set */
    count = 0;
/*fprintf(stderr,"readASNseq: AsnReadId\n");*/
    while ((atp = AsnReadId(aip, amp, atp)) != NULL) {
      if (atp == atp2)  {  /* top level Seq-entry */
        the_set = SeqEntryAsnRead(aip, atp);
        SeqEntryToRaw(the_set, false, whichEntry, nseq, &seq, seqid, seqlen);
        SeqEntryFree(the_set);
        if (*nseq >= whichEntry) goto goodexit;
        }
      else
        AsnReadVal(aip, atp, NULL);
      count++;
      }
    }

goodexit:
  AsnIoClose(aip);
  *error= 0;
  return seq;

errxit:
  AsnIoClose(aip);
  *error= eASNerr;
  if (seq) free(seq);
  return NULL;
}
Exemplo n.º 9
0
/** Initializes the XML output structure and prints the XML output header. 
 * @param aip ASN.1 output stream [in]
 * @param program BLAST program name [in]
 * @param database BLAST database name [in]
 * @param query_loc Query Seq-loc [in]
 * @param flags Flag for query sequence inclusion [in]
 * @param search_params BLAST search parameters [in]
 * @return Initialized structure for printing XML output.
 */
static MBXml* 
s_MBXmlInit(AsnIo* aip, char* program, char* database, 
          SeqLoc* query_loc, Int4 flags, Blast_SearchParams* search_params)
{
    MBXml* xmlp;
    AsnModule* amp;
    DataVal av;
    AsnType* atp;
    Boolean retval = FALSE;

    AsnType*       BLASTOUTPUT;
    AsnType*       BLASTOUTPUT_program;
    AsnType*       BLASTOUTPUT_version;
    AsnType*       BLASTOUTPUT_reference;
    AsnType*       BLASTOUTPUT_db;
    AsnType*       BLASTOUTPUT_query_ID;
    AsnType*       BLASTOUTPUT_query_def;
    AsnType*       BLASTOUTPUT_query_len;
    AsnType*       BLASTOUTPUT_query_seq;
    AsnType*       BLASTOUTPUT_param;
    AsnType*       BLASTOUTPUT_iterations;
    AsnType*       BLASTOUTPUT_iterations_E;
    AsnType*       BLASTOUTPUT_mbstat;

    if (strcmp(program, "rpsblast") == 0)
       program = "blastp";
    else if (strcmp(program, "rpstblastn") == 0)
       program = "blastx";

    AsnSetXMLmodulePrefix("http://www.ncbi.nlm.nih.gov/dtd/");
    xmlp = (MBXml*) MemNew(sizeof(MBXml));
    
    xmlp->aip = aip;
    
    if (! bxmlobjAsnLoad()) {
        return NULL;
    }
    
    amp = AsnAllModPtr();

    MACRO_atp_find(BLASTOUTPUT,BlastOutput);
    MACRO_atp_find(BLASTOUTPUT_program,BlastOutput.program);
    MACRO_atp_find(BLASTOUTPUT_version,BlastOutput.version);
    MACRO_atp_find(BLASTOUTPUT_reference,BlastOutput.reference);
    MACRO_atp_find(BLASTOUTPUT_db,BlastOutput.db);
    MACRO_atp_find(BLASTOUTPUT_query_ID,BlastOutput.query-ID);
    MACRO_atp_find(BLASTOUTPUT_query_def,BlastOutput.query-def);
    MACRO_atp_find(BLASTOUTPUT_query_len,BlastOutput.query-len);
    MACRO_atp_find(BLASTOUTPUT_query_seq,BlastOutput.query-seq);
    MACRO_atp_find(BLASTOUTPUT_param,BlastOutput.param);
    MACRO_atp_find(BLASTOUTPUT_iterations,BlastOutput.iterations);
    MACRO_atp_find(BLASTOUTPUT_iterations_E,BlastOutput.iterations.E);
    MACRO_atp_find(BLASTOUTPUT_mbstat,BlastOutput.mbstat);

    /* Start of iterations structure */
    xmlp->atp = BLASTOUTPUT_iterations_E;

    /* Head of all BlastOutput structure */
    xmlp->BlastOutput = BLASTOUTPUT;
    
    /* Head of iterations strucure */
    xmlp->BlastOutput_iterations = BLASTOUTPUT_iterations;

    /* Head of the final statistics for Mega BLAST */
    xmlp->BlastOutput_mbstat = BLASTOUTPUT_mbstat;
    
    xmlp->boutp = s_CreateBlastOutputHead(program, database, query_loc, flags, search_params);
    
    atp = AsnLinkType(NULL, BLASTOUTPUT);   /* link local tree */
    
    if (atp == NULL) {
        return NULL;
    }
    
    if (! AsnOpenStruct(xmlp->aip, atp, (Pointer) xmlp->boutp)) {
        return NULL;
    }

    if (xmlp->boutp->program != NULL) {
        av.ptrvalue = xmlp->boutp -> program;
        retval = AsnWrite(xmlp->aip, BLASTOUTPUT_program,  &av);
    }
    
    if (xmlp->boutp->version != NULL) {
        av.ptrvalue = xmlp->boutp->version;
        retval = AsnWrite(xmlp->aip, BLASTOUTPUT_version,  &av);
    }
    
    if (xmlp->boutp->reference != NULL) {
        av.ptrvalue = xmlp->boutp->reference;
        retval = AsnWrite(xmlp->aip, BLASTOUTPUT_reference,  &av);
    }

    if (xmlp->boutp -> db != NULL) {
        av.ptrvalue = xmlp->boutp->db;
        retval = AsnWrite(xmlp->aip, BLASTOUTPUT_db,  &av);
    }

    if (xmlp->boutp -> query_ID != NULL) {
        av.ptrvalue = xmlp->boutp->query_ID;
        retval = AsnWrite(xmlp->aip, BLASTOUTPUT_query_ID,  &av);
    }

    if (xmlp->boutp->query_def != NULL) {
        av.ptrvalue = xmlp->boutp->query_def;
        retval = AsnWrite(xmlp->aip, BLASTOUTPUT_query_def,  &av);
    }

    av.intvalue = xmlp->boutp->query_len;
    retval = AsnWrite(xmlp->aip, BLASTOUTPUT_query_len,  &av);

    if (xmlp->boutp->query_seq != NULL) {
        av.ptrvalue = xmlp->boutp->query_seq;
        retval = AsnWrite(xmlp->aip, BLASTOUTPUT_query_seq,  &av);
    }

    if (xmlp->boutp->param != NULL) {
        if (!ParametersAsnWrite(xmlp->boutp->param, 
                                xmlp->aip, BLASTOUTPUT_param)) {
            return NULL;
        }
    }

    if(!AsnOpenStruct(xmlp->aip, BLASTOUTPUT_iterations, NULL))
        return NULL;
    
    AsnIoFlush(xmlp->aip);
    
    return xmlp;
}
Exemplo n.º 10
0
Int2 Main (void)

{
  Char            app [64], type;
  CSpeedFlagData  cfd;
  CharPtr         directory, filter, infile, logfile, outfile, str, suffix;
  Boolean         remote;
  time_t          runtime, starttime, stoptime;

  /* standard setup */

  ErrSetFatalLevel (SEV_MAX);
  ErrClearOptFlags (EO_SHOW_USERSTR);
  UseLocalAsnloadDataAndErrMsg ();
  ErrPathReset ();

  /* finish resolving internal connections in ASN.1 parse tables */

  if (! AllObjLoad ()) {
    Message (MSG_FATAL, "AllObjLoad failed");
    return 1;
  }
  if (! SubmitAsnLoad ()) {
    Message (MSG_FATAL, "SubmitAsnLoad failed");
    return 1;
  }
  if (! FeatDefSetLoad ()) {
    Message (MSG_FATAL, "FeatDefSetLoad failed");
    return 1;
  }
  if (! SeqCodeSetLoad ()) {
    Message (MSG_FATAL, "SeqCodeSetLoad failed");
    return 1;
  }
  if (! GeneticCodeTableLoad ()) {
    Message (MSG_FATAL, "GeneticCodeTableLoad failed");
    return 1;
  }

  /* process command line arguments */

  sprintf (app, "cspeedtest %s", CSPEEDTEST_APPLICATION);
  if (! GetArgs (app, sizeof (myargs) / sizeof (Args), myargs)) {
    return 0;
  }

  MemSet ((Pointer) &cfd, 0, sizeof (CSpeedFlagData));

  directory = (CharPtr) myargs [p_argInputPath].strvalue;
  infile = (CharPtr) myargs [i_argInputFile].strvalue;
  outfile = (CharPtr) myargs [o_argOutputFile].strvalue;
  filter = (CharPtr) myargs [f_argFilter].strvalue;
  suffix = (CharPtr) myargs [x_argSuffix].strvalue;

  cfd.batch = FALSE;
  cfd.binary = (Boolean) myargs [b_argBinary].intvalue;
  cfd.compressed = (Boolean) myargs [c_argCompressed].intvalue;
  cfd.lock = (Boolean) myargs [l_argLockFar].intvalue;
  cfd.type = 1;

  str = myargs [a_argType].strvalue;
  TrimSpacesAroundString (str);
  if (StringDoesHaveText (str)) {
    type = str [0];
  } else {
    type = 'a';
  }

  type = TO_LOWER (type);
  switch (type) {
    case 'a' :
      cfd.type = 1;
      break;
    case 'e' :
      cfd.type = 2;
      break;
    case 'b' :
      cfd.type = 3;
      break;
    case 's' :
      cfd.type = 4;
      break;
    case 'm' :
      cfd.type = 5;
      break;
    case 't' :
      cfd.type = 1;
      cfd.batch = TRUE;
      break;
    case 'f' :
      cfd.type = 6;
      break;
    case 'l' :
      cfd.type = 7;
      break;
    default :
      cfd.type = 1;
      break;
  }

  remote = (Boolean) myargs [R_argRemote].intvalue;

  cfd.maxcount = myargs [X_argMaxCount].intvalue;
  if (cfd.maxcount < 1) {
    cfd.maxcount = 1;
  }

  cfd.io = myargs [O_argInOut].strvalue;
  cfd.clean = myargs [K_argClean].strvalue;
  cfd.skip = myargs [P_argSkip].strvalue;
  cfd.index = myargs [I_argIndex].strvalue;
  cfd.seq = myargs [S_argSeq].strvalue;
  cfd.feat = myargs [F_argFeat].strvalue;
  cfd.desc = myargs [D_argDesc].strvalue;
  cfd.verify = myargs [V_argVerify].strvalue;

  cfd.amp = AsnAllModPtr ();
  cfd.atp_bss = AsnFind ("Bioseq-set");
  cfd.atp_bsss = AsnFind ("Bioseq-set.seq-set");
  cfd.atp_se = AsnFind ("Bioseq-set.seq-set.E");
  cfd.atp_bsc = AsnFind ("Bioseq-set.class");
  cfd.bssp_atp = AsnLinkType (NULL, cfd.atp_bss);

  logfile = (CharPtr) myargs [L_argLogFile].strvalue;
  if (StringDoesHaveText (logfile)) {
    cfd.logfp = FileOpen (logfile, "w");
  }

  if (remote) {
    PubSeqFetchEnable ();
  }

  if (StringDoesHaveText (outfile)) {
    cfd.ofp = FileOpen (outfile, "w");
  }

  starttime = GetSecs ();

  if (StringDoesHaveText (directory)) {

    DirExplore (directory, NULL, suffix, FALSE, ProcessOneRecord, (Pointer) &cfd);

  } else if (StringDoesHaveText (infile)) {

    ProcessOneRecord (infile, (Pointer) &cfd);
  }

  if (cfd.ofp != NULL) {
    FileClose (cfd.ofp);
  }

  stoptime = GetSecs ();
  runtime = stoptime - starttime;
  if (cfd.logfp != NULL) {
    fprintf (cfd.logfp, "Finished in %ld seconds\n", (long) runtime);
    FileClose (cfd.logfp);
  }
  printf ("Finished in %ld seconds\n", (long) runtime);

  if (remote) {
    PubSeqFetchDisable ();
  }

  return 0;
}