Int2 Main(void) { Int4 StsCount = 0, StsInvalid = 0; STSHashPtr PNTR StsHashTable; STSDbNamesPtr db_name; if (!GetArgs("setsts",NUMARGS,dump_args)) { return 1; } if (!ErrSetLog (LogFileName)) { ErrShow(); } else { ErrSetOpts (ERR_CONTINUE, ERR_LOG_ON); } db_name = MemNew(sizeof(STSDbNames)); db_name->sts_db_name = StsName; db_name->sts_map_name = MapName; db_name->sts_org_name = OrgName; if((StsHashTable = InitHashTable(db_name, &StsCount, &StsInvalid)) == NULL) { ErrLogPrintf("Error in initialization of Hash Table. Exiting..."); return 1; } ErrLogPrintf("Invalid database entries found: %d\n", StsInvalid); ErrLogPrintf("Hash table created with %d sequences\n", StsCount); if((StsCount = DumpHashTable(db_name, StsHashTable)) < 0) { ErrLogPrintf("Error in dumping of Hash Table. Exiting..."); return 1; } ErrLogPrintf("Map file dumped with %d sequences\n", StsCount); return 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); }
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); }
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; }