static void CommentFieldsToDialog (DialoG d, Pointer data) { TagListPtr tlp; ValNodePtr fields, vnp; CharPtr str; tlp = (TagListPtr) GetObjectExtra (d); if (tlp == NULL) { return; } fields = (ValNodePtr) data; tlp->vnp = ValNodeFreeData (tlp->vnp); SendMessageToDialog (tlp->dialog, VIB_MSG_RESET); for (vnp = fields; vnp != NULL; vnp = vnp->next) { str = TagStringFromFieldRule (vnp->data.ptrvalue); if (str != NULL) { ValNodeAddPointer (&(tlp->vnp), 0, str); } } SendMessageToDialog (tlp->dialog, VIB_MSG_REDRAW); tlp->max = MAX ((Int2) 0, (Int2) (ValNodeLen (tlp->vnp) - tlp->rows)); CorrectBarMax (tlp->bar, tlp->max); CorrectBarPage (tlp->bar, tlp->rows - 1, tlp->rows - 1); if (tlp->max > 0) { SafeShow (tlp->bar); } else { SafeHide (tlp->bar); } }
void FreeCSAN(PCSAN pcsanThis) { if (pcsanThis->next) FreeCSAN(pcsanThis->next); if (pcsanThis->pcSeqName) MemFree(pcsanThis->pcSeqName); if (pcsanThis->pvnSeqAlnPart) ValNodeFreeData(pcsanThis->pvnSeqAlnPart); if (pcsanThis->pcSeqAln) MemFree(pcsanThis->pcSeqAln); return; }
static ValNodePtr FetchItemFieldValuesFree (ValNodePtr field_values) { ValNodePtr vnp; for (vnp = field_values; vnp != NULL; vnp = vnp->next) { vnp->data.ptrvalue = ValNodeFreeData (vnp->data.ptrvalue); } field_values = ValNodeFree (field_values); return field_values; }
static void DoReleaseFile (CharPtr inputFile, Boolean binary, Boolean compressed, FILE *fp, AsnIoPtr aop, AsnTypePtr atp_se) { ScanData sd; StringSetPtr ssp; ValNodePtr vnp; fprintf (fp, "\n***** %s *****\n\n", inputFile); sd.fp = fp; sd.aop = aop; sd.atp_se = atp_se; StringCpy (sd.buf, "?"); sd.bulk = FALSE; sd.cgList = NULL; sd.lcList = NULL; sd.impCdsCount = 0; sd.recordCount = 0; ScanBioseqSetRelease (inputFile, binary, compressed, (Pointer) &sd, DoRecord); for (vnp = sd.cgList; vnp != NULL; vnp = vnp->next) { ssp = (StringSetPtr) vnp->data.ptrvalue; if (ssp == NULL) continue; fprintf (sd.fp, "CG - %s (%ld) - %s\n", ssp->firstID, (long) ssp->count, ssp->text); } for (vnp = sd.lcList; vnp != NULL; vnp = vnp->next) { ssp = (StringSetPtr) vnp->data.ptrvalue; if (ssp == NULL) continue; fprintf (sd.fp, "LC - %s (%ld) - %s\n", ssp->firstID, (long) ssp->count, ssp->text); } if (sd.impCdsCount != 0) { fprintf (sd.fp, "IC - (%ld)\n", (long) sd.impCdsCount); } sd.cgList = ValNodeFreeData (sd.cgList); sd.lcList = ValNodeFreeData (sd.lcList); fprintf (fp, "\n\n!!!!! %s - %ld records !!!!!\n\n", inputFile, (long) sd.recordCount); }
/****************************************************************** * * free_cvp_list(cvp_list) * free a list of CodonVectorPtr * ******************************************************************/ NLM_EXTERN ValNodePtr free_cvp_list(ValNodePtr cvp_list) { ValNodePtr next; CodonVectorPtr cvp; Int2 i; while(cvp_list) { next = cvp_list->next; cvp_list->next = NULL; cvp = cvp_list->data.ptrvalue; for(i=0; i<3; ++i) MemFree(cvp->buf[i]); SeqIdFree(cvp->sip); ValNodeFreeData(cvp_list); cvp_list = next; } return NULL; }
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; }
static void DoGraphs (BioseqPtr bsp, Pointer userdata) { Byte bases [400]; ByteStorePtr bs; Int2 ctr, i, j, val; Int4 curroffset = 0, gphlen = 0, seqlen = 0, slplen, bslen, min = INT4_MAX, max = INT4_MIN, NsWithScore, ACGTsWithoutScore; DeltaSeqPtr dsp; Uint2 entityID, olditemid = 0, olditemtype = 0, numdsp = 0, numsgp = 0; GphItemPtr gip; ValNodePtr head, vnp; Boolean noErrors = TRUE; Uint1 residue; ScanDataPtr sdp; SeqGraphPtr sgp; SeqIntPtr sintp; SeqLocPtr slocp; SeqLitPtr slp; SeqPortPtr spp; Char str [128]; if (bsp == NULL) return; if (! ISA_na (bsp->mol)) return; if (SeqMgrGetParentOfPart (bsp, NULL) != NULL) return; sdp = (ScanDataPtr) userdata; entityID = ObjMgrGetEntityIDForPointer (bsp); head = GetSeqGraphsOnBioseq (entityID, bsp); if (head == NULL) return; for (vnp = head; vnp != NULL; vnp = vnp->next) { gip = (GphItemPtr) vnp->data.ptrvalue; if (gip == NULL) continue; sgp = gip->sgp; min = MIN ((Int4) min, (Int4) sgp->min.intvalue); max = MAX ((Int4) max, (Int4) sgp->max.intvalue); if (sgp->min.intvalue < 0 || sgp->min.intvalue > 100) { sprintf (str, "Graph min (%ld) out of range", (long) sgp->min.intvalue); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } if (sgp->max.intvalue < 0 || sgp->max.intvalue > 100) { sprintf (str, "Graph max (%ld) out of range", (long) sgp->max.intvalue); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } gphlen += sgp->numval; bs = (ByteStorePtr) sgp->values; if (bs != NULL) { bslen = BSLen (bs); if (sgp->numval != bslen) { sprintf (str, "SeqGraph (%ld) and ByteStore (%ld) length mismatch", (long) sgp->numval, (long) bslen); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } } } if (bsp->repr == Seq_repr_raw) { seqlen = bsp->length; } else if (bsp->repr == Seq_repr_delta) { for (dsp = (DeltaSeqPtr) (bsp->seq_ext); dsp != NULL; dsp = dsp->next) { switch (dsp->choice) { case 1 : slocp = (SeqLocPtr) dsp->data.ptrvalue; if (slocp == NULL) break; if (slocp->choice != SEQLOC_NULL) { seqlen += SeqLocLen (slocp); } break; case 2 : slp = (SeqLitPtr) dsp->data.ptrvalue; if (slp == NULL || slp->seq_data == NULL) break; seqlen += slp->length; break; default : break; } } } if (seqlen != gphlen) { sprintf (str, "SeqGraph (%ld) and Bioseq (%ld) length mismatch", (long) gphlen, (long) seqlen); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } if (bsp->repr == Seq_repr_delta) { for (dsp = (DeltaSeqPtr) (bsp->seq_ext), vnp = head; dsp != NULL && vnp != NULL; dsp = dsp->next) { gip = (GphItemPtr) vnp->data.ptrvalue; if (gip == NULL) continue; sgp = gip->sgp; if (sgp == NULL) continue; switch (dsp->choice) { case 1 : slocp = (SeqLocPtr) dsp->data.ptrvalue; if (slocp != NULL && slocp->choice != SEQLOC_NULL) { slplen = SeqLocLen (slocp); curroffset += slplen; if (sgp->numval != slplen) { sprintf (str, "SeqGraph (%ld) and SeqLoc (%ld) length mismatch", (long) sgp->numval, (long) slplen); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } numdsp++; if (vnp != NULL) { vnp = vnp->next; numsgp++; } } break; case 2 : slp = (SeqLitPtr) dsp->data.ptrvalue; if (slp != NULL && slp->seq_data != NULL) { if (sgp->numval != slp->length) { sprintf (str, "SeqGraph (%ld) and SeqLit (%ld) length mismatch", (long) sgp->numval, (long) slp->length); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } slocp = sgp->loc; if (slocp != NULL && slocp->choice == SEQLOC_INT) { sintp = (SeqIntPtr) slocp->data.ptrvalue; if (sintp != NULL) { if (sintp->from != curroffset) { sprintf (str, "SeqGraph (%ld) and SeqLit (%ld) start do not coincide", (long) sintp->from, (long) curroffset); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } if (sintp->to != slp->length + curroffset - 1) { sprintf (str, "SeqGraph (%ld) and SeqLit (%ld) stop do not coincide", (long) sintp->to, (long) (slp->length + curroffset - 1)); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } } } numdsp++; if (vnp != NULL) { vnp = vnp->next; numsgp++; } } if (slp != NULL) { curroffset += slp->length; } break; default : break; } } if (numdsp != numsgp) { sprintf (str, "Different number of SeqGraph (%d) and SeqLit (%d) components", (int) numsgp, (int) numdsp); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } } for (vnp = head; vnp != NULL; vnp = vnp->next) { gip = (GphItemPtr) vnp->data.ptrvalue; if (gip == NULL) continue; sgp = gip->sgp; if (sgp == NULL) continue; spp = SeqPortNewByLoc (sgp->loc, Seq_code_iupacna); if (spp == NULL) continue; slplen = SeqLocLen (sgp->loc); if (bsp->repr == Seq_repr_delta || bsp->repr == Seq_repr_virtual) { SeqPortSet_do_virtual (spp, TRUE); } bs = (ByteStorePtr) sgp->values; BSSeek (bs, 0, SEEK_SET); j = 0; val = 0; ctr = SeqPortRead (spp, bases, sizeof (bases)); i = 0; residue = (Uint1) bases [i]; NsWithScore = 0; ACGTsWithoutScore = 0; while (residue != SEQPORT_EOF && j < sgp->numval) { if (IS_residue (residue)) { val = (Int2) BSGetByte (bs); j++; switch (residue) { case 'A' : case 'C' : case 'G' : case 'T' : if (val == 0) { ACGTsWithoutScore++; } break; case 'N' : if (val > 0) { NsWithScore++; } break; default : break; } } i++; if (i >= ctr) { i = 0; ctr = SeqPortRead (spp, bases, sizeof (bases)); if (ctr < 0) { bases [0] = -ctr; } else if (ctr < 1) { bases [0] = SEQPORT_EOF; } } residue = (Uint1) bases [i]; } if (ACGTsWithoutScore > 0) { sprintf (str, "%ld ACGT bases have zero score value", (long) ACGTsWithoutScore); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } if (NsWithScore > 0) { sprintf (str, "%ld N bases have positive score value", (long) NsWithScore); PrintGraphMessage (bsp, sdp, str, NULL); noErrors = FALSE; } SeqPortFree (spp); } if (noErrors) { PrintGraphMessage (bsp, sdp, "Quality scores okay", NULL); } ValNodeFreeData (head); }
Int2 Main (void) { CharPtr base, directory, organism, ptr; Boolean altstart, findorf, flatfile, validate; ValNodePtr head, vnp; 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; } if (! FeatDefSetLoad ()) { Message (MSG_FATAL, "FeatDefSetLoad failed"); return 1; } if (! GetArgs ("sgd2asn", sizeof (myargs) / sizeof (Args), myargs)) { return 0; } directory = (CharPtr) myargs [0].strvalue; base = (CharPtr) myargs [1].strvalue; organism = (CharPtr) myargs [2].strvalue; findorf = (Boolean) myargs [3].intvalue; altstart = (Boolean) myargs [4].intvalue; validate = (Boolean) myargs [5].intvalue; flatfile = (Boolean) myargs [6].intvalue; if (! StringHasNoText (base)) { ptr = StringStr (base, ".fsa"); if (ptr != NULL) { *ptr = '\0'; ProcessOneRecord (directory, base, organism, findorf, altstart, validate, flatfile); } } else { head = DirCatalog (directory); for (vnp = head; vnp != NULL; vnp = vnp->next) { if (vnp->choice == 0) { base = (CharPtr) vnp->data.ptrvalue; if (! StringHasNoText (base)) { ptr = StringStr (base, ".fsa"); if (ptr != NULL) { *ptr = '\0'; ProcessOneRecord (directory, base, organism, findorf, altstart, validate, flatfile); } } } } ValNodeFreeData (head); } return 0; }
static void ProcessOneRecord ( CharPtr directory, CharPtr base, CharPtr organism, Boolean findorf, Boolean altstart, Boolean validate, Boolean flatfile ) { BioSourcePtr biop = NULL; BioseqPtr bsp; Uint2 datatype, entityID; Int2 genCode; MolInfoPtr mip; SeqAnnotPtr sap; SeqEntryPtr sep; SeqFeatPtr sfp; SqnTagPtr stp; CharPtr ttl; ValNodePtr vnp; Message (MSG_POST, "Processing %s\n", base); bsp = (BioseqPtr) ReadOneFile (directory, base, "fsa", &datatype); if (bsp == NULL || datatype != OBJ_BIOSEQ) { ObjMgrFree (datatype, (Pointer) bsp); return; } if (bsp->mol == Seq_mol_na) { bsp->mol = Seq_mol_dna; } vnp = ValNodeExtract (&(bsp->descr), Seq_descr_title); if (vnp != NULL) { ttl = (CharPtr) vnp->data.ptrvalue; if (ttl != NULL) { stp = SqnTagParse (ttl); if (stp != NULL) { biop = OldParseTitleIntoBioSource (stp, bsp, organism); } SqnTagFree (stp); } ValNodeFreeData (vnp); } if (biop == NULL) { biop = OldParseTitleIntoBioSource (NULL, bsp, organism); } if (biop != NULL) { SeqDescrAddPointer (&(bsp->descr), Seq_descr_source, (Pointer) biop); } mip = MolInfoNew (); if (mip != NULL) { mip->biomol = MOLECULE_TYPE_GENOMIC; SeqDescrAddPointer (&(bsp->descr), Seq_descr_molinfo, (Pointer) mip); } entityID = ObjMgrRegister (datatype, (Pointer) bsp); sep = GetBestTopParentForData (entityID, bsp); genCode = SeqEntryToGeneticCode (sep, NULL, NULL, 0); if (findorf) { AnnotateBestOrf (bsp, genCode, altstart); } sap = (SeqAnnotPtr) ReadOneFile (directory, base, "tbl", &datatype); if (sap != NULL && datatype == OBJ_SEQANNOT && sap->type == 1) { sap->next = bsp->annot; bsp->annot = sap; } else { ObjMgrFree (datatype, (Pointer) sap); } /* for parsed in features or best ORF, promote CDS products to protein bioseq */ for (sap = bsp->annot; sap != NULL; sap = sap->next) { if (sap->type == 1) { SetEmptyGeneticCodes (sap, genCode); sfp = (SeqFeatPtr) sap->data; PromoteXrefs (sfp, bsp, entityID); } } sep = GetTopSeqEntryForEntityID (entityID); if (sep != NULL) { SeriousSeqEntryCleanup (sep, NULL, NULL); WriteOneFile (directory, base, "sqn", sep); if (validate || flatfile) { SeqMgrIndexFeatures (entityID, 0); } if (validate) { Message (MSG_POST, "Validating %s\n", base); ValidateOneFile (directory, base, "val", sep); } if (flatfile) { Message (MSG_POST, "Flatfile %s\n", base); sep = FindNucSeqEntry (sep); FlatfileOneFile (directory, base, "gbf", sep); } } ObjMgrFreeByEntityID (entityID); }
NLM_EXTERN Nlm_Int4 Nlm_DirExplore ( Nlm_CharPtr directory, Nlm_CharPtr filter, Nlm_CharPtr suffix, Nlm_Boolean recurse, Nlm_DirExpProc proc, Nlm_VoidPtr userdata ) { Nlm_Int4 count = 0; Nlm_Char file [FILENAME_MAX], path [PATH_MAX]; Nlm_CharPtr ptr, str; ValNodePtr head, vnp; if (proc == NULL) return 0; if (Nlm_StringHasNoText (directory) /* || Nlm_StringHasNoText (suffix) */ ) return 0; /* get list of all files in source directory */ head = Nlm_DirCatalog (directory); for (vnp = head; vnp != NULL; vnp = vnp->next) { if (vnp->choice == 0) { str = (Nlm_CharPtr) vnp->data.ptrvalue; if (! Nlm_StringHasNoText (str)) { /* check filename for indicated suffix */ ptr = Nlm_StringStr (str, suffix); if (ptr != NULL) { /* make sure detected suffix is really at end of filename */ if (Nlm_StringCmp (ptr, suffix) == 0) { *ptr = '\0'; } else { ptr = NULL; } } if (Nlm_StringHasNoText (suffix) || ptr != NULL) { Nlm_StringNCpy_0 (path, directory, sizeof (path)); sprintf (file, "%s%s", str, suffix); Nlm_FileBuildPath (path, NULL, file); /* check full path/file name for desired filter */ if (Nlm_StringHasNoText (filter) || Nlm_StringStr (path, filter) != NULL) { /* process file that satisfies optional filter and suffix constraints */ proc (path, userdata); count++; } } } } else if (vnp->choice == 1 && recurse) { /* recurse into subdirectory */ Nlm_StringNCpy_0 (path, directory, sizeof (path)); str = (Nlm_CharPtr) vnp->data.ptrvalue; Nlm_FileBuildPath (path, str, NULL); count += Nlm_DirExplore (path, filter, suffix, recurse, proc, userdata); } } /* clean up file list */ ValNodeFreeData (head); return count; }
/* return -1 on failure, 0 on success */ static Int4 FileRecurse ( CharPtr directory, InputStreamPtr isp, OutputStreamPtr osp, AsnStreamPtr asp, Int4Ptr gap_sizes ) { Char path [PATH_MAX]; CharPtr ptr; CharPtr str; ValNodePtr head, vnp; CharPtr orig_dir, orig_base; Int4 rval = 0; /* get list of all files in source directory */ head = DirCatalog (directory); for (vnp = head; vnp != NULL; vnp = vnp->next) { if (vnp->choice == 0) { str = (CharPtr) vnp->data.ptrvalue; if (StringDoesHaveText (str)) { /* does filename have desired substring? */ ptr = StringStr (str, osp->suffix); if (ptr != NULL) { /* make sure detected suffix is really at end of filename */ if (StringCmp (ptr, osp->suffix) == 0) { *ptr = '\0'; /* process file that has desired suffix (usually .fsa) */ osp->base = str; orig_dir = isp->directory; isp->directory = directory; orig_base = isp->base; isp->base = str; if (isp->is_binary) { rval |= ProcessStream (isp, osp, asp, gap_sizes); } else { rval |= ProcessOneRecord (directory, osp, gap_sizes); } isp->directory = orig_dir; isp->base = orig_base; osp->base = NULL; } } } } else if (vnp->choice == 1) { /* recurse into subdirectory */ StringNCpy_0 (path, directory, sizeof (path)); str = (CharPtr) vnp->data.ptrvalue; FileBuildPath (path, str, NULL); rval |= FileRecurse (path, isp, osp, asp, gap_sizes); } } /* clean up file list */ ValNodeFreeData (head); return rval; }
Int2 Main (void) { CharPtr base, directory, outfile, suffix, ptr; BioseqSetPtr bssp; ValNodePtr head, vnp; SeqEntryPtr sep; SeqSubmitPtr ssp; /* 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 */ if (! GetArgs ("subfuse", sizeof (myargs) / sizeof (Args), myargs)) { return 0; } directory = (CharPtr) myargs [p_argInputPath].strvalue; outfile = (CharPtr) myargs [o_argOutputFile].strvalue; suffix = (CharPtr) myargs [x_argSuffix].strvalue; bssp = BioseqSetNew (); if (bssp == NULL) return 0; bssp->_class = BioseqseqSet_class_genbank; sep = SeqEntryNew (); if (sep == NULL) return 0; sep->choice = 2; sep->data.ptrvalue = (Pointer) bssp; ssp = SeqSubmitNew (); if (ssp == NULL) return 0; ssp->datatype = 1; ssp->data = (Pointer) sep; /* get list of all files in source directory */ head = DirCatalog (directory); for (vnp = head; vnp != NULL; vnp = vnp->next) { if (vnp->choice == 0) { base = (CharPtr) vnp->data.ptrvalue; if (! StringHasNoText (base)) { ptr = StringStr (base, suffix); if (ptr != NULL) { *ptr = '\0'; Message (MSG_POST, "Processing %s\n", base); ProcessOneRecord (ssp, bssp, directory, base, suffix); } } } } /* clean up file list */ ValNodeFreeData (head); /* write output file */ WriteOneSubmission (outfile, ssp); return 0; }
Int2 Main (void) { Int2 argcount; Boolean flagHaveNet; Int4 gi; SeqEntryPtr sep; ComPatPtr cpp, cpph = NULL; SeqAlignPtr sap, sapn; StdSegPtr ssp; SeqLocPtr slp, slpn; Int4 start, stop; FILE *fiop; Char fastafile[256], namesfile[256]; CharPtr title; CharPtr taxon; FloatHi mw; ValNodePtr namelist = NULL; static CharPtr pattern_file = "ncbipros.dat"; static CharPtr protease_file = "ncbiendo.dat"; static CharPtr names_file = "ncbipnam.dat"; static GatherScope gs; GatherScopePtr gsp; static Gather_PBS gpbs; Gather_PBSPtr gpbsp; #ifndef NO_TAX_NET Int4 i; static Char taxdata[8]; static Gather_TaxId gti; Gather_TaxIdPtr gtip; #endif #ifndef NO_TAX_NET Int2 ia=4, ib=5, ic=6, id=7, ie=8, ig=9, ih=10, ii=11; #else Int2 ib=4, ic=5, id=6, ie=7, ig=8, ih=9, ii=10; #endif argcount = sizeof (myargs) / sizeof (Args); if (!GetArgs ("ProSiteSearch", argcount, myargs)) return 1; if (myargs[0].intvalue == 0 && myargs[1].strvalue == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 100, "No gi or FastA file given :: for help : srchaa -"); ErrShow (); exit (1); } gsp = &gs; #ifndef NO_TAX_NET gtip = >i; #endif gpbsp = &gpbs; MemSet ((Pointer) gsp, 0, sizeof (GatherScope)); MemSet ((Pointer) gsp->ignore, (int) (TRUE), (size_t) (OBJ_MAX * sizeof (Boolean))); gsp->ignore[OBJ_SEQDESC] = TRUE; gsp->ignore[OBJ_BIOSEQ] = FALSE; gpbsp->bsp = NULL; gi = myargs[0].intvalue; if (myargs[1].strvalue != NULL) StrCpy (fastafile, myargs[1].strvalue); else fastafile[0] = '\0'; if (gi > 0) { if (!EntrezInit ("srchaa", FALSE, &flagHaveNet)) { ErrPostEx (SEV_ERROR, TOP_ERROR, 102, "Entrez init failed"); ErrShow (); exit (1); } } #ifndef NO_TAX_NET if (myargs[ia].intvalue) { if (!TaxArchInit ()) { ErrPostEx (SEV_ERROR, TOP_ERROR, 103, "Taxonomy init failed"); ErrShow (); exit (1); } } #endif fiop = NULL; if (gi > 0) { sep = EntrezSeqEntryGet (gi, SEQENTRY_READ_BIOSEQ); } else { if ((fiop = FileOpen (fastafile, "r")) == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 103, "Failed to open FastA file: %s", fastafile); ErrShow (); exit (1); } sep = FastaToSeqEntry (fiop, FALSE); } if (sep == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 104, "No seqentry found"); ErrShow (); exit (1); } while (sep != NULL) { gsp->ignore[OBJ_SEQDESC] = TRUE; gsp->ignore[OBJ_BIOSEQ] = FALSE; gpbsp->bsp = NULL; gpbsp->gi = gi; GatherSeqEntry (sep, (Pointer) gpbsp, GetBioseq, (Pointer) gsp); taxon = NULL; #ifndef NO_TAX_NET if (myargs[ia].intvalue) { for (i = 0; i < 8; i++) taxdata[i] = '-'; taxon = taxdata; gsp->ignore[OBJ_SEQDESC] = FALSE; gsp->ignore[OBJ_BIOSEQ] = TRUE; gtip->taxid = 0; GatherSeqEntry (sep, (Pointer) gtip, GetTaxId, (Pointer) gsp); if (gtip->taxid != 0) WhatOrg (gtip->taxid, taxon); else taxon = NULL; } #endif if (gpbsp->bsp != NULL) { if (ISA_aa (gpbsp->bsp->mol)) { if (cpph == NULL) { namesfile[0] = '\0'; if (myargs[id].intvalue) StrCpy (namesfile, names_file); if (myargs[ie].strvalue != NULL) StrCpy (namesfile, myargs[ie].strvalue); if (myargs[ig].strvalue != NULL) { if ((cpph = CompilePattern (myargs[ig].strvalue, 1)) != NULL) StrCpy (cpph->name, "User Pattern"); } else { namelist = ReadPatternNames (namesfile); if (myargs[ib].intvalue) cpph = ReadPrositePattern (protease_file, (Boolean) myargs[2].intvalue, myargs[3].intvalue, taxon, NULL); else cpph = ReadPrositePattern (pattern_file, (Boolean) myargs[2].intvalue, myargs[3].intvalue, taxon, namelist); } } if (!(Boolean) myargs[ih].intvalue) { title = FastaTitle (gpbsp->bsp, ">", NULL); printf ("%s\n", title); MemFree (title); } cpp = cpph; while (cpp != NULL) { sap = PatternMatchBioseq (gpbsp->bsp, cpp, (Int4)myargs[ii].intvalue); if (myargs[ib].intvalue) { printf (">%s\n", cpp->name); if (sap != NULL) printf (" Start Stop M.W.\n"); } if (myargs[ib].intvalue) { EmbedMolecularWeightInfo (sap, gpbsp->bsp); if (myargs[ic].intvalue) URK_SeqAlignSortByMolWt (&sap); while (sap != NULL) { ssp = (StdSegPtr) sap->segs; slp = ssp->loc; start = SeqLocStart (slp); stop = SeqLocStop (slp); mw = ssp->scores->value.realvalue; printf ("%8ld %8ld %9.2f\n", (long) start+1, (long) stop+1, mw); sapn = sap->next; SeqAlignFree (sap); sap = sapn; } } else { slp = MatchSa2Sl (&sap); if (myargs[ih].intvalue && slp != NULL) { title = FastaTitle (gpbsp->bsp, ">", NULL); printf ("%s\n", title); MemFree (title); } while (slp != NULL) { start = SeqLocStart (slp); stop = SeqLocStop (slp); printf ("%8ld %8ld %s\n", (long) start+1, (long) stop+1, cpp->name); slpn = slp->next; SeqLocFree (slp); slp = slpn; } } cpp = cpp->nextpattern; } } else { ErrPostEx (SEV_ERROR, TOP_ERROR, 106, "Not a protein bioseq"); ErrShow (); exit (1); } } else { ErrPostEx (SEV_ERROR, TOP_ERROR, 105, "No bioseq found"); ErrShow (); exit (1); } SeqEntryFree (sep); sep = NULL; if (fiop != NULL) sep = FastaToSeqEntry (fiop, FALSE); } ComPatFree (cpph); ValNodeFreeData (namelist); FileClose (fiop); if (gi > 0) EntrezFini (); #ifndef NO_TAX_NET if (myargs[ia].intvalue) TaxArchFini (); #endif return 0; }
/******************************************************************************* Function : DDV_GetRulerForEditor() Purpose : create the ruler for the editor. This new descriptor is created using the descriptor of the viewer. Return value : an allocated data block ready for use by the editor. Null if failure *******************************************************************************/ NLM_EXTERN ValNodePtr DDV_GetRulerForEditor(ValNodePtr descr_head,Int4 from_disp, Int4 to_disp) { DDVRulerDescrPtr drdp,prev_drdp,new_drdp; ValNodePtr vnp2,vnp3,vnpDesc; Int4 cumulDecr,drdp_size,beginCopy,endCopy,drdp_start_ali; Boolean bPop; cumulDecr=0; vnpDesc=NULL; prev_drdp=NULL; for(vnp2=descr_head;vnp2!=NULL;vnp2=vnp2->next){ drdp=(DDVRulerDescrPtr)vnp2->data.ptrvalue; drdp_size=drdp->disp_stop-drdp->disp_start+1; /*not yet in the region of interest ?*/ if (drdp->disp_stop<from_disp) { cumulDecr+=drdp_size; continue; } beginCopy=_max_(from_disp,drdp->disp_start); endCopy=_min_(drdp->disp_stop,to_disp); if (drdp->bUnAligned==FALSE) drdp_start_ali=drdp->align_start+(beginCopy-drdp->disp_start); else drdp_start_ali=(Int4)-1; /*in order to merge nodes of same type, i keep track of the previous populated drdp node. Same style==yes, then just extend to the right the previous node*/ if (prev_drdp){ if (prev_drdp->bUnAligned==drdp->bUnAligned){ prev_drdp->disp_stop=endCopy; bPop=TRUE; } else{ bPop=FALSE; } } else{ bPop=FALSE; } if (!bPop){ new_drdp=(DDVRulerDescrPtr)MemNew(sizeof(DDVRulerDescr)); if (!new_drdp) goto erreur; new_drdp->disp_start=beginCopy; new_drdp->disp_stop=endCopy; new_drdp->align_start=drdp_start_ali; new_drdp->bUnAligned=drdp->bUnAligned; if (!vnpDesc){ vnp3=ValNodeAddPointer(&vnpDesc,0,(Pointer)new_drdp); } else{ vnp3=ValNodeAddPointer(&vnp3,0,(Pointer)new_drdp); } prev_drdp=new_drdp; } if (drdp->disp_stop>=to_disp) break; cumulDecr+=drdp_size; } return(vnpDesc); erreur: if (vnpDesc) ValNodeFreeData(vnpDesc); return(NULL); }