/***************************************************************************** * * PubEquivAsnRead(aip, atp) * atp is the current type (if identifier of a parent struct) * assumption is readIdent has occurred * if atp == NULL, then assumes it stands alone and read ident * has not occurred. * *****************************************************************************/ NLM_EXTERN ValNodePtr LIBCALL PubEquivAsnRead (AsnIoPtr aip, AsnTypePtr orig) { DataVal av; AsnTypePtr atp, oldtype; ValNodePtr anp=NULL, cit, curr; Boolean first; if (! loaded) { if (! PubAsnLoad()) return anp; } if (aip == NULL) return anp; first = TRUE; if (orig == NULL) /* PubEquiv ::= (self contained) */ oldtype = AsnReadId(aip, amp, PUB_EQUIV); else oldtype = AsnLinkType(orig, PUB_EQUIV); /* link in local tree */ if (oldtype == NULL) return anp; if (AsnReadVal(aip, oldtype, &av) <= 0) /* read START_STRUCT */ goto erret; atp = oldtype; curr = NULL; anp = NULL; while ((atp = AsnReadId(aip, amp, atp)) != oldtype) { if (atp == NULL) goto erret; cit = PubAsnRead(aip, atp); if (cit == NULL) goto erret; if (first) { anp = cit; first = FALSE; } else { curr->next = cit; } curr = cit; } if (AsnReadVal(aip, oldtype, &av) <= 0) /* read END_STRUCT for SET OF */ goto erret; ret: AsnUnlinkType(orig); /* unlink local tree */ return anp; erret: anp = PubEquivFree(anp); goto ret; }
NLM_EXTERN ValNodePtr LIBCALL AsnGenericValNodeSetAsnRead ( AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr orig, BoolPtr isError, AsnReadFunc readfunc, AsnOptFreeFunc freefunc ) { AsnTypePtr atp = orig, start_atp; DataVal av; Pointer val; ValNodePtr vnp, head = NULL, last = NULL; if (isError != NULL) { *isError = FALSE; } if (aip == NULL || readfunc == NULL || freefunc == NULL) return NULL; if (AsnReadVal (aip, atp, &av) <= 0) goto erret; /* read START STRUCT */ start_atp = orig; atp = start_atp; while ((atp = AsnReadId (aip, amp, atp)) != start_atp) { val = (Pointer) readfunc (aip, atp); if (val == NULL) goto erret; vnp = ValNodeAddPointer (&last, 0, val); if (head == NULL) { head = vnp; } last = vnp; } if (AsnReadVal (aip, atp, &av) <= 0) goto erret; /* read END STRUCT */ ret: return (Pointer) head; erret: head = AsnGenericValNodeSetFree (head, freefunc); if (isError != NULL) { *isError = TRUE; } goto ret; }
NLM_EXTERN Pointer LIBCALL AsnGenericChoiceSeqOfAsnRead (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr orig, BoolPtr isError, AsnReadFunc readfunc, AsnOptFreeFunc freefunc) { AsnTypePtr start_atp; ValNodePtr current; ValNodePtr head = NULL; ValNodePtr prev = NULL; AsnTypePtr atp = orig; DataVal av; if (isError != NULL) *isError = FALSE; if (aip == NULL) return NULL; if (AsnReadVal (aip, atp, &av) <= 0) /* START_STRUCT */ goto erret; start_atp = atp; while ((atp = AsnReadId (aip, amp, atp)) != start_atp) { if (atp == NULL) goto erret; current = (ValNodePtr) readfunc (aip, atp); if (current == NULL) goto erret; if (head == NULL) head = current; else prev->next = current; prev = current; } if (AsnReadVal (aip, atp, &av) <= 0) /* END_STRUCT */ goto erret; ret: return (Pointer) head; erret: head = (ValNodePtr) freefunc (head); if (isError != NULL) *isError = TRUE; goto ret; }
static Int4 ProcessStream (InputStreamPtr isp, OutputStreamPtr osp, AsnStreamPtr asp, Int4Ptr gap_sizes) { AsnTypePtr atp, atp_srch; AsnIoPtr asn_in, asn_out; Int4 rval = 0; SeqEntryPtr sep; Uint2 entityID; DataVal av; if (isp == NULL || osp == NULL || asp == NULL || gap_sizes == NULL) return 1; asn_in = AsnIoFromInputStream (isp); asn_out = AsnIoFromOutputStream (osp); if (isp->is_seqentry) { atp = asp->atp_se; atp_srch = asp->atp_se; } else { atp = asp->atp_bss; atp_srch = asp->atp_bss_se; } while ((atp = AsnReadId(asn_in, asp->amp, atp)) != NULL && rval == 0) { if (atp != atp_srch) { AsnReadVal(asn_in, atp, &av); AsnWrite(asn_out, atp, &av); AsnKillValue(atp, &av); continue; } if ((sep = SeqEntryAsnRead(asn_in, atp)) == NULL) { Message (MSG_POSTERR, "SeqEntryAsnRead failure"); rval = 1; } else { entityID = ObjMgrRegister (OBJ_SEQENTRY, sep); ProcessSeqEntry (sep, gap_sizes); if (! SeqEntryAsnWrite(sep, asn_out, atp)) { Message (MSG_POSTERR, "SeqEntryAsnWrite failure"); rval = 1; } AsnIoFlush(asn_out); ObjMgrFreeByEntityID (entityID); } } /* Endwhile, AsnReadId */ AsnIoClose(asn_in); if (asn_out != osp->aip) { AsnIoClose(asn_out); } return rval; }
/***************************************************************************** * * 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); }
NLM_EXTERN ValNodePtr LIBCALL AsnGenericBaseSeqOfAsnRead (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr orig, int whichvalslot, BoolPtr isError) { AsnTypePtr start_atp; ValNodePtr current; ValNodePtr head = NULL; ValNodePtr prev = NULL; AsnTypePtr atp = orig; DataVal av; if (isError != NULL) *isError = FALSE; if (aip == NULL) return NULL; if (AsnReadVal (aip, atp, &av) <= 0) /* START_STRUCT */ goto erret; start_atp = atp; while ((atp = AsnReadId (aip, amp, atp)) != start_atp) { if (atp == NULL) goto erret; current = ValNodeNew (prev); if (current == NULL) goto erret; switch (whichvalslot) { case ASNCODE_PTRVAL_SLOT: case ASNCODE_BYTEVAL_SLOT: if (AsnReadVal (aip, atp, &av) <= 0) goto erret; current->data.ptrvalue = av.ptrvalue; break; case ASNCODE_REALVAL_SLOT: if (AsnReadVal (aip, atp, &av) <= 0) goto erret; current->data.realvalue = av.realvalue; break; case ASNCODE_INTVAL_SLOT: if (AsnReadVal (aip, atp, &av) <= 0) goto erret; current->data.intvalue = av.intvalue; break; case ASNCODE_BIGINTVAL_SLOT: if (AsnReadVal (aip, atp, &av) <= 0) goto erret; current->data.bigintvalue = av.bigintvalue; break; case ASNCODE_BOOLVAL_SLOT: if (AsnReadVal (aip, atp, &av) <= 0) goto erret; current->data.boolvalue = av.boolvalue; break; } if (head == NULL) head = current; else prev->next = current; prev = current; } if (AsnReadVal (aip, atp, &av) <= 0) /* END_STRUCT */ goto erret; ret: return head; erret: head = ValNodeFree (head); if (isError != NULL) *isError = TRUE; goto ret; }
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); }
/***************************************************************************** * * PubSetAsnRead(aip, atp) * atp is the current type (if identifier of a parent struct) * assumption is readIdent has occurred * if atp == NULL, then assumes it stands alone and read ident * has not occurred. * *****************************************************************************/ NLM_EXTERN ValNodePtr LIBCALL PubSetAsnRead (AsnIoPtr aip, AsnTypePtr orig) { DataVal av; AsnTypePtr atp, settype; Pointer pnt; ValNodePtr anp=NULL, cit, curr; Uint1 choice; AsnReadFunc func; Boolean first; if (! loaded) { if (! PubAsnLoad()) return anp; } if (aip == NULL) return anp; if (orig == NULL) /* PubSet ::= (self contained) */ atp = AsnReadId(aip, amp, PUB_SET); else atp = AsnLinkType(orig, PUB_SET); /* link in local tree */ if (atp == NULL) return anp; anp = ValNodeNew(NULL); if (anp == NULL) goto erret; if (AsnReadVal(aip, atp, &av) <= 0) /* read the CHOICE value (nothing) */ goto erret; settype = AsnReadId(aip, amp, atp); /* find the choice */ if (settype == NULL) goto erret; if (AsnReadVal(aip, settype, &av) <= 0) /* read START_STRUCT */ goto erret; if (settype == PUB_SET_pub) { choice = 1; func = (AsnReadFunc) PubAsnRead; } else if (settype == PUB_SET_medline) { choice = 3; func = (AsnReadFunc) MedlineEntryAsnRead; } else if (settype == PUB_SET_article) { choice = 5; func = (AsnReadFunc) CitArtAsnRead; } else if (settype == PUB_SET_journal) { choice = 6; func = (AsnReadFunc) CitJourAsnRead; } else if (settype == PUB_SET_book) { choice = 7; func = (AsnReadFunc) CitBookAsnRead; } else if (settype == PUB_SET_proc) { choice = 8; func = (AsnReadFunc) CitBookAsnRead; } else if (settype == PUB_SET_patent) { choice = 9; func = (AsnReadFunc) CitPatAsnRead; } anp->choice = choice; first = TRUE; curr = NULL; while ((atp = AsnReadId(aip, amp, settype)) != settype) { if (atp == NULL) goto erret; pnt = (* func)(aip, atp); if (pnt == NULL) goto erret; if (settype == PUB_SET_pub) /* already a Pub */ { cit = (ValNodePtr)pnt; } else /* make into a Pub */ { cit = ValNodeNew(NULL); if (cit == NULL) goto erret; cit->data.ptrvalue = pnt; cit->choice = choice; } if (first) { anp->data.ptrvalue = (Pointer)cit; first = FALSE; } else { curr->next = cit; } curr = cit; } if (AsnReadVal(aip, settype, &av) <= 0) /* read END_STRUCT for SET OF */ goto erret; if (anp == NULL) ErrPost(CTX_NCBIOBJ, 1, "Empty SET OF Pub. line %ld", aip->linenumber); ret: AsnUnlinkType(orig); /* unlink local tree */ return anp; erret: anp = PubSetFree(anp); goto ret; }
/***************************************************************************** * * PubAsnRead(aip, atp) * atp is the current type (if identifier of a parent struct) * assumption is readIdent has occurred * if atp == NULL, then assumes it stands alone and read ident * has not occurred. * *****************************************************************************/ NLM_EXTERN ValNodePtr LIBCALL PubAsnRead (AsnIoPtr aip, AsnTypePtr orig) { DataVal av; AsnTypePtr atp; ValNodePtr anp=NULL; Uint1 choice = 0; AsnReadFunc func = NULL; if (! loaded) { if (! PubAsnLoad()) return anp; } if (aip == NULL) return anp; if (orig == NULL) /* Pub ::= (self contained) */ atp = AsnReadId(aip, amp, PUB); else atp = AsnLinkType(orig, PUB); /* link in local tree */ if (atp == NULL) return anp; anp = ValNodeNew(NULL); if (anp == NULL) goto erret; if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* read the CHOICE value (nothing) */ atp = AsnReadId(aip, amp, atp); /* find the choice */ if (atp == NULL) goto erret; if (atp == PUB_gen) { choice = 1; func = (AsnReadFunc) CitGenAsnRead; } else if (atp == PUB_sub) { choice = 2; func = (AsnReadFunc) CitSubAsnRead; } else if (atp == PUB_medline) { choice = 3; func = (AsnReadFunc) MedlineEntryAsnRead; } else if (atp == PUB_muid) { choice = 4; if (AsnReadVal(aip, atp, &anp->data) <= 0) goto erret; } else if (atp == PUB_article) { choice = 5; func = (AsnReadFunc) CitArtAsnRead; } else if (atp == PUB_journal) { choice = 6; func = (AsnReadFunc) CitJourAsnRead; } else if (atp == PUB_book) { choice = 7; func = (AsnReadFunc) CitBookAsnRead; } else if (atp == PUB_proc) { choice = 8; func = (AsnReadFunc) CitProcAsnRead; } else if (atp == PUB_patent) { choice = 9; func = (AsnReadFunc) CitPatAsnRead; } else if (atp == PUB_pat_id) { choice = 10; func = (AsnReadFunc) IdPatAsnRead; } else if (atp == PUB_man) { choice = 11; func = (AsnReadFunc) CitLetAsnRead; } else if (atp == PUB_equiv) { choice = 12; func = (AsnReadFunc) PubEquivAsnRead; } else if (atp == PUB_pmid) { choice = 13; if (AsnReadVal(aip, atp, &anp->data) <= 0) goto erret; } anp->choice = choice; if ((choice != 4) && (choice != 13) && func != NULL) { anp->data.ptrvalue = (* func)(aip, atp); if (anp->data.ptrvalue == NULL) goto erret; } ret: AsnUnlinkType(orig); /* unlink local tree */ return anp; erret: anp = PubFree(anp); goto ret; }
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; }
/***************************************************************************** * * LinkSetAsnRead(aip, atp) * atp is the current type (if identifier of a parent struct) * assumption is readIdent has occurred * if atp == NULL, then assumes it stands alone and read ident * has not occurred. * *****************************************************************************/ NLM_EXTERN LinkSetPtr LIBCALL LinkSetAsnRead (AsnIoPtr aip, AsnTypePtr orig) { DataVal av; AsnTypePtr atp; LinkSetPtr lsp=NULL; Int4 num, i; Int4Ptr ptr; if (! loaded) { if (! AccessAsnLoad()) return lsp; } if (aip == NULL) return lsp; if (orig == NULL) /* LinkSet ::= (self contained) */ atp = AsnReadId(aip, amp, LINK_SET); else atp = AsnLinkType(orig, LINK_SET); /* link in local tree */ if (atp == NULL) return lsp; lsp = LinkSetNew(); if (lsp == NULL) goto erret; if (AsnReadVal(aip, atp, &av) <= 0) /* read the start struct */ goto erret; atp = AsnReadId(aip, amp, atp); /* find the num */ if (atp == NULL) goto erret; if (AsnReadVal(aip, atp, &av) <= 0) /* get the num */ goto erret; num = av.intvalue; lsp->num = num; atp = AsnReadId(aip, amp, atp); /* start seq of uids */ if (atp == NULL) goto erret; if (AsnReadVal(aip, atp, &av) <= 0) goto erret; ptr = (Int4Ptr)MemNew((size_t)(sizeof(Int4) * (num + 1))); /* 0 sentinel at end */ if (ptr == NULL) goto erret; lsp->uids = ptr; i = 0; while ((atp = AsnReadId(aip, amp, atp)) == LINK_SET_uids_E) { if (AsnReadVal(aip, atp, &av) <= 0) goto erret; ptr[i] = av.intvalue; i++; if (i > num) break; } if (atp == NULL) goto erret; if (i != num) { ErrPost(CTX_NCBIOBJ, 0, "Incorrect number of uids in Link-set. line %ld", aip->linenumber); goto erret; } if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end seq of */ atp = AsnReadId(aip, amp, atp); if (atp == NULL) goto erret; if (atp == LINK_SET_weights) { if (AsnReadVal(aip, atp, &av) <= 0) goto erret; ptr = (Int4Ptr)MemNew((size_t)(sizeof(Int4) * (num + 1))); /* 0 sentinel at end */ if (ptr == NULL) goto erret; lsp->weights = ptr; i = 0; while ((atp = AsnReadId(aip, amp, atp)) == LINK_SET_weights_E) { if (AsnReadVal(aip, atp, &av) <= 0) goto erret; ptr[i] = av.intvalue; i++; if (i > num) break; } if (atp == NULL) goto erret; if (i != num) { ErrPost(CTX_NCBIOBJ, 0, "Incorrect number of weights in Link-set. line %ld", aip->linenumber); goto erret; } if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end seq of */ if ((atp = AsnReadId(aip, amp, atp)) == NULL) goto erret; } if (AsnReadVal(aip, atp, &av) <= 0) goto erret; /* end struct */ ret: AsnUnlinkType(orig); /* unlink local tree */ return lsp; erret: lsp = LinkSetFree(lsp); goto ret; }
static void ProcessMultipleRecord ( CharPtr filename, CSpeedFlagPtr cfp ) { AsnIoPtr aip; AsnTypePtr atp; BioseqPtr bsp; Char buf [41]; Uint2 entityID; FILE *fp; SeqEntryPtr fsep; Char longest [41]; Int4 numrecords, x; SeqEntryPtr sep; time_t starttime, stoptime, worsttime; #ifdef OS_UNIX Char cmmd [256]; CharPtr gzcatprog; int ret; Boolean usedPopen = FALSE; #endif if (cfp == NULL) return; if (StringHasNoText (filename)) return; #ifndef OS_UNIX if (cfp->compressed) { Message (MSG_POSTERR, "Can only decompress on-the-fly on UNIX machines"); return; } #endif #ifdef OS_UNIX if (cfp->compressed) { gzcatprog = getenv ("NCBI_UNCOMPRESS_BINARY"); if (gzcatprog != NULL) { sprintf (cmmd, "%s %s", gzcatprog, filename); } else { ret = system ("gzcat -h >/dev/null 2>&1"); if (ret == 0) { sprintf (cmmd, "gzcat %s", filename); } else if (ret == -1) { Message (MSG_POSTERR, "Unable to fork or exec gzcat in ScanBioseqSetRelease"); return; } else { ret = system ("zcat -h >/dev/null 2>&1"); if (ret == 0) { sprintf (cmmd, "zcat %s", filename); } else if (ret == -1) { Message (MSG_POSTERR, "Unable to fork or exec zcat in ScanBioseqSetRelease"); return; } else { Message (MSG_POSTERR, "Unable to find zcat or gzcat in ScanBioseqSetRelease - please edit your PATH environment variable"); return; } } } fp = popen (cmmd, /* cfp->binary? "rb" : */ "r"); usedPopen = TRUE; } else { fp = FileOpen (filename, cfp->binary? "rb" : "r"); } #else fp = FileOpen (filename, cfp->binary? "rb" : "r"); #endif if (fp == NULL) { Message (MSG_POSTERR, "FileOpen failed for input file '%s'", filename); return; } aip = AsnIoNew (cfp->binary? ASNIO_BIN_IN : ASNIO_TEXT_IN, fp, NULL, NULL, NULL); if (aip == NULL) { Message (MSG_ERROR, "AsnIoNew failed for input file '%s'", filename); return; } if (cfp->logfp != NULL) { fprintf (cfp->logfp, "%s\n\n", filename); fflush (cfp->logfp); } longest [0] = '\0'; worsttime = 0; numrecords = 0; atp = cfp->atp_bss; while ((atp = AsnReadId (aip, cfp->amp, atp)) != NULL) { if (atp == cfp->atp_se) { sep = SeqEntryAsnRead (aip, atp); if (sep != NULL) { entityID = ObjMgrGetEntityIDForChoice (sep); fsep = FindNthBioseq (sep, 1); if (fsep != NULL && fsep->choice == 1) { bsp = (BioseqPtr) fsep->data.ptrvalue; if (bsp != NULL) { SeqIdWrite (bsp->id, buf, PRINTID_FASTA_LONG, sizeof (buf)); if (cfp->logfp != NULL) { fprintf (cfp->logfp, "%s\n", buf); fflush (cfp->logfp); } } } starttime = GetSecs (); for (x = 0; x < cfp->maxcount; x++) { DoProcess (sep, entityID, cfp); } stoptime = GetSecs (); if (stoptime - starttime > worsttime) { worsttime = stoptime - starttime; StringCpy (longest, buf); } numrecords++; ObjMgrFreeByEntityID (entityID); } } else { AsnReadVal (aip, atp, NULL); } } AsnIoFree (aip, FALSE); #ifdef OS_UNIX if (usedPopen) { pclose (fp); } else { FileClose (fp); } #else FileClose (fp); #endif if (cfp->logfp != NULL && (! StringHasNoText (longest))) { fprintf (cfp->logfp, "Longest processing time %ld seconds on %s\n", (long) worsttime, longest); fprintf (cfp->logfp, "Total number of records %ld\n", (long) numrecords); fflush (cfp->logfp); } }