Boolean tax_addDivision(Int4 div_id, CharPtr div_cde, CharPtr div_txt) { Int2 i; if(tax_div == NULL) { tax_div= MemNew(sizeof(TaxDivision)*div_alloced); if(tax_div == NULL) return FALSE; for(i= 0; i < div_alloced; i++) { tax_div[i].div_cde[0]= tax_div[i].div_cde[3]= tax_div[i].div_txt[0]= tax_div[i].div_txt[63]= '\0'; } } if(div_id < 0) return FALSE; if(div_id >= div_alloced) { TaxDivisionPtr tmp= MemMore(tax_div, sizeof(TaxDivision)*(div_id + 8)); if(tmp == NULL) return FALSE; tax_div= tmp; for(i= div_alloced; i < div_id + 8; i++) { tax_div[i].div_cde[0]= tax_div[i].div_cde[3]= tax_div[i].div_txt[0]= tax_div[i].div_txt[63]= '\0'; } div_alloced= div_id + 8; } StringNCpy(tax_div[div_id].div_cde, div_cde, 3); StringNCpy(tax_div[div_id].div_txt, div_txt, 63); return TRUE; }
Boolean tax_addRank(Int2 rank_id, CharPtr rank_txt) { Int2 i; rank_id+= d_rank; if(tax_rank == NULL) { tax_rank= MemNew(sizeof(TaxRank)*rank_alloced); if(tax_rank == NULL) return FALSE; for(i= 0; i < rank_alloced; i++) { tax_rank[i].rank_txt[0]= tax_rank[i].rank_txt[63]= '\0'; } } if(rank_id < 0) return FALSE; if(rank_id >= rank_alloced) { TaxRankPtr tmp= MemMore(tax_rank, sizeof(TaxRank)*(rank_id + 8)); if(tmp == NULL) return FALSE; tax_rank= tmp; for(i= rank_alloced; i < rank_id + 8; i++) { tax_rank[i].rank_txt[0]= tax_rank[i].rank_txt[63]= '\0'; } rank_alloced= rank_id + 8; } StringNCpy(tax_rank[rank_id].rank_txt, rank_txt, 63); return TRUE; }
Boolean tax_addNameClass(Int4 class_cde, CharPtr class_txt, Int4 priority) { Int2 i; if(name_class == NULL) { name_class= MemNew(sizeof(TaxNameClass)*class_alloced); if(name_class == NULL) return FALSE; for(i= 0; i < class_alloced; i++) { name_class[i].priority= 1000; name_class[i].class_txt[0]= name_class[i].class_txt[33]= '\0'; } } if(class_cde < 0) return FALSE; if(class_cde >= class_alloced) { TaxNameClassPtr tmp= MemMore(name_class, sizeof(TaxNameClass)*(class_cde + 8)); if(tmp == NULL) return FALSE; name_class= tmp; for(i= class_alloced; i < class_cde + 8; i++) { name_class[i].priority= 1000; name_class[i].class_txt[0]= name_class[i].class_txt[33]= '\0'; } class_alloced= class_cde + 8; } name_class[class_cde].priority= priority; StringNCpy(name_class[class_cde].class_txt, class_txt, 33); return TRUE; }
/*---------------- replace original seq_id by local_id --------------*/ void AssignLocaIdToBiostruc(SeqIdPtr sip, Char *PDBName, Char Chain,BiostrucPtr bsp) { BiostrucDescrPtr pbsdrThis = NULL; MoleculeGraphPtr pmgThis = NULL; BiomolDescrPtr pbmdrThis = NULL; Char ThisPDBName[Local_max], *ThisChain; StringCpy(ThisPDBName, PDBNAME_DEFAULT); pbsdrThis = ValNodeFindNext(bsp->descr, NULL, BiostrucDescr_name); if(pbsdrThis) StringNCpy(ThisPDBName, pbsdrThis ->data.ptrvalue, 4); /*if(StringCmp(PDBName, ThisPDBName) != 0) { printf("Something is wrong!\n"); return; } */ pmgThis = bsp->chemical_graph->molecule_graphs; while(pmgThis) { /* loop over molecule_graphs to match chain */ pbmdrThis = ValNodeFindNext(pmgThis->descr, NULL, BiomolDescr_name); if(pbmdrThis){ ThisChain = StringSave((CharPtr)pbmdrThis->data.ptrvalue); } else ThisChain = StringSave(STRING_UNK_MOL); if(Chain == *ThisChain) { pmgThis->seq_id = sip; return; } pmgThis = pmgThis->next; } }
Boolean tax_addGC(Int2 gc_id, CharPtr gc_txt) { Int2 i; if(tax_gc == NULL) { tax_gc= MemNew(sizeof(TaxGenCode)*gc_alloced); if(tax_gc == NULL) return FALSE; for(i= 0; i < gc_alloced; i++) { tax_gc[i].gc_name[0]= tax_gc[i].gc_name[127]= '\0'; } } if(gc_id < 0) return FALSE; if(gc_id >= gc_alloced) { TaxGenCodePtr tmp= MemMore(tax_gc, sizeof(TaxGenCode)*(gc_id + 8)); if(tmp == NULL) return FALSE; tax_gc= tmp; for(i= gc_alloced; i < gc_id + 8; i++) { tax_gc[i].gc_name[0]= tax_gc[i].gc_name[127]= '\0'; } gc_alloced= gc_id + 8; } StringNCpy(tax_gc[gc_id].gc_name, gc_txt, 127); return TRUE; }
static void Cn3D_ExportPDB(IteM i) { PDNMS pdnmsThis = NULL; PMSD pmsdThis = NULL; Char pcSavestr[60]; Char pcSavename[32]; CharPtr Cn3D_pcPDBName; GrouP g, g2, g3, g4; GrouP gMS; ButtoN b; if (Cn3D_Export_InUse) return; else Cn3D_Export_InUse = TRUE; pdnmsThis = GetSelectedModelstruc(); if (!pdnmsThis) { Cn3D_Export_InUse = FALSE; return; } pmsdThis = (PMSD) pdnmsThis->data.ptrvalue; Cn3D_wPDBSave = ModalWindow(-20, -13, -10, -10, NULL); /* set up a group encolosing structures - models selection lists and - "info strings" */ Cn3D_pcPDBName = StringSave(GetStrucStrings(pdnmsThis, PDB_ACC)); sprintf(pcSavestr, "Save %s As a PDB Formatted File ...", Cn3D_pcPDBName); g = HiddenGroup(Cn3D_wPDBSave, 0, 3, NULL); SetGroupMargins(g, 10, 10); SetGroupSpacing(g, 10, 5); StaticPrompt(g, pcSavestr, 0, 0, systemFont, 'l'); g2 = HiddenGroup(g, 2, 0, NULL); SetGroupMargins(g2, 10, 10); SetGroupSpacing(g2, 10, 5); StringNCpy(pcSavename, Cn3D_pcPDBName, 8); StringCat(pcSavename, ".pdb"); Cn3D_tPDBSave = DialogText(g2, pcSavename, 18, (TxtActnProc) Cn3D_PDBEnableProc); MemFree(Cn3D_pcPDBName); Cn3D_bPDBBrowse = PushButton(g2, " browse...", (BtnActnProc) Cn3D_PDBBrowseProc); g3 = HiddenGroup(g, 2, 0, NULL); gMS = Cn3D_ModelSelect(g3, FALSE); /* no vector models for PDB files saves */ g4 = HiddenGroup(g3, 0, 2, NULL); SetGroupMargins(g4, 10, 10); SetGroupSpacing(g4, 10, 5); Cn3D_bPDBOk = PushButton(g4, "OK", Cn3D_ExportPDBNow); b = PushButton(g4, "Cancel", Cn3D_CancelPDB); Cn3D_PDBEnableProc(NULL); Select(Cn3D_bPDBOk); /* disable appropriate stuff here */ Cn3D_DisableFileOps(); Show(Cn3D_wPDBSave); return; }
/*---------------- make a new SeqEntry ------------------------*/ NcbiMimeAsn1Ptr ScreenSequence( NcbiMimeAsn1Ptr pvnNcbi, CharPtr JobID) { BiostrucAlignPtr pbsaStruct = NULL; BiostrucAnnotSetPtr pbsaThis = NULL, pbsaHead = NULL; BiostrucFeatureSetPtr pbsfsThis = NULL; BiostrucFeaturePtr pbsfThis = NULL; SeqEntryPtr sepHead = NULL, sepHeadNew = NULL, sepThis = NULL; /*Char PDBName[Local_max], */ Char Chain, Domain; CharPtr pSegmentSlave; pbsaStruct = pvnNcbi->data.ptrvalue; pbsaThis = pbsaStruct->alignments; pbsfsThis = pbsaThis->features; pbsfThis = pbsfsThis->features; StringNCpy(pSegmentMaster, pbsfThis->name, 6); /* StringNCpy(PDBName, pSegmentMaster, 4); */ Chain = pSegmentMaster[4]; sepHead = pbsaStruct->sequences; /*if(JobID){ sepThis = SeqEntryNew(); sepThis->choice = 1; sepThis->data.ptrvalue = sepHead->data.ptrvalue; } else */ sepThis = ExtractThisSep(sepHead, Chain); ValNodeLink(&sepHeadNew, sepThis); sepHead = sepHead->next; while(pbsfThis){ pSegmentSlave = StringSave(&pbsfThis->name[7]); pSegmentSlave[6]='\0'; /*StringNCpy(PDBName, pSegmentSlave, 4);*/ Chain = pSegmentSlave[4]; sepThis = ExtractThisSep(sepHead, Chain); ValNodeLink(&sepHeadNew, sepThis); pbsfThis = pbsfThis->next; sepHead = sepHead->next; } pbsaStruct->sequences = sepHeadNew; MemFree(pSegmentSlave); return(pvnNcbi); }
NLM_EXTERN SeqIdReplaceListPtr ReadSeqIdPairListFromFile (FILE *fp) { ReadBufferData rbd; CharPtr linestring, cp, id2, buf = NULL; Int4 len, buf_len = 0; SeqIdPairPtr pair; ValNodePtr pair_list = NULL, last = NULL, vnp; SeqIdReplaceListPtr replace_list = NULL; if (fp == NULL) return NULL; rbd.fp = fp; rbd.current_data = NULL; linestring = AbstractReadFunction (&rbd); while (linestring != NULL && linestring[0] != EOF) { cp = linestring + StringSpn (linestring, " \t"); if (*cp != 0) { len = StringCSpn (cp, " \t"); id2 = cp + len + StringSpn (cp + len, " \t"); if (*id2 != 0) { if (len + 1 > buf_len) { buf = MemFree (buf); buf_len = len + 1; buf = (CharPtr) MemNew (sizeof (Char) * buf_len); } StringNCpy (buf, cp, len); buf[len] = 0; pair = SeqIdPairNew (); pair->sip_find = MakeSeqID (buf); SeqIdWrite (pair->sip_find, pair->buf_find, PRINTID_REPORT, sizeof (pair->buf_find) - 1); pair->sip_replace = MakeSeqID (id2); vnp = ValNodeNew (NULL); vnp->data.ptrvalue = pair; if (last == NULL) { pair_list = vnp; } else { last->next = vnp; } last = vnp; } } free (linestring); linestring = AbstractReadFunction (&rbd); } pair_list = ValNodeSort (pair_list, SortSeqIdPairList); replace_list = SeqIdReplaceListNew (pair_list); pair_list = SeqIdPairListFree (pair_list); return replace_list; }
DocUid LIBCALL MMDBEvalPDB (CharPtr str) { Char eval[10]; StringNCpy(eval, str, 4); StrUpper(eval); eval[4] = '\0'; #ifdef MMDB_PUBSTRUCT if(!file_db) return PubStruct_pdb2mmdb( (database[0]?database:NULL), eval); #endif return MMDBEvalPDB_fb (eval); }
static Boolean Get_Params (void) { FILE *f; FILE *g; Int4 i; Int2 j; Int4 len; Int4 num_nuc; Int4 num_prt; if (GetArgs ("suggest", NUMARG, myargs)) { if (NUMARG == TOTARG && myargs [8].intvalue) { suggestRec.lookForStop = (Boolean) (myargs [6].intvalue); StringNCpy (inputFile, myargs [0].strvalue, sizeof (inputFile)); if (inputFile [0] == '\0') { StringCpy (inputFile, "stdin"); } StringNCpy (outputFile, myargs [1].strvalue, sizeof (outputFile)); if (outputFile [0] == '\0') { StringCpy (outputFile, "stdout"); } f = FileOpen (inputFile, "r"); if (f != NULL) { Get_DNA (f, &suggestRec); FileClose (f); dna_seq = suggestRec.nucleotide.sequence; dna_len = StringLen (dna_seq); if (dna_len > 3 && dna_seq != NULL) { dna_len -= 3; dna_seq [dna_len] = '\0'; } rev_seq = MemNew(dna_len+1); if (rev_seq != NULL) { reverse (dna_len); f = FileOpen (outputFile, "w"); if (f != NULL) { j = 0; for (i = 0; i < dna_len; i++) { fputc ((int) (rev_seq [i]), f); j++; if (j >= 50) { fputc ((int) '\n', f); j = 0; } } if (j > 0) { fputc ((int) '\n', f); } FileClose (f); } } } } else { suggestRec.lookForStop = (Boolean) (myargs [6].intvalue); StringNCpy (inputFile, myargs [0].strvalue, sizeof (inputFile)); if (inputFile [0] == '\0') { StringCpy (inputFile, "stdin"); } StringNCpy (outputFile, myargs [1].strvalue, sizeof (outputFile)); if (outputFile [0] == '\0') { StringCpy (outputFile, "stdout"); } f = FileOpen (inputFile, "r"); if (f != NULL) { g = FileOpen (outputFile, "w"); if (g != NULL) { suggestOut.out.fileOut = g; while (! feof (f)) { if ((Boolean) (myargs [7].intvalue)) { Get_DNA (f, &suggestRec); Get_Protein (f, &suggestRec); } else { Get_Protein (f, &suggestRec); Get_DNA (f, &suggestRec); } Get_Genetic_Code (myargs [2].intvalue, &suggestRec); suggestRec.minVal = (myargs [3].intvalue); suggestRec.maxVal = (myargs [4].intvalue); suggestRec.minExon = (myargs [5].intvalue); ProcessData(&suggestOut); } FileClose (g); } FileClose (f); } } return TRUE; } else { return FALSE; } }
/*---------------- to assign local id to identical chain ---------------*/ NcbiMimeAsn1Ptr CheckId(NcbiMimeAsn1Ptr pvnNcbi, CharPtr JobID) { /* to assign local id to identical chain so that to work around */ /* object manager for messaging */ /* yanli */ BiostrucAlignPtr pbsaStruct = NULL; BiostrucPtr pbsMaster = NULL, pbsSlaveHead = NULL; BiostrucAnnotSetPtr pbsaThis = NULL, pbsaHead = NULL; SeqAnnotPtr psaAlignHead = NULL; SeqEntryPtr sepHead; BiostrucFeatureSetPtr pbsfsThis = NULL, pbsfsHead = NULL; BiostrucFeaturePtr pbsfThis = NULL, pbsfHead = NULL; SeqAlignPtr salpHead; SeqIdPtr sip, sip_cpy, sipMaster, sip_temp; ObjectIdPtr oipMaster, oip; Int4 iCount1 = 0, iCount_ID = 0; Boolean IdChainFound = FALSE; CharPtr pSegmentSlave; Char PDBName[Local_max], Chain, Domain; Char AlignIdStr[Local_max]; Int4 AlignId; typedef struct local_string{ Char str[Local_max]; }Local_String, PNTR Local_StringPtr; Local_String **str; pvnNcbi = ScreenSequence(pvnNcbi, JobID); pbsaStruct = pvnNcbi->data.ptrvalue; pbsaThis = pbsaStruct->alignments; pbsSlaveHead = pbsaStruct->slaves; sepHead = pbsaStruct->sequences; psaAlignHead = pbsaStruct->seqalign; pbsfsThis = pbsaThis->features; pbsfThis = pbsfsThis->features; /* from vastsrv page, we are always considering one */ /* domain of the master, so no loop for pbsfsThis */ StringNCpy(pSegmentMaster, pbsfThis->name, 6); pSegmentMaster[6]='\0'; /*pSegmentMaster[0]=pbsfThis->name[0]; pSegmentMaster[1]=pbsfThis->name[1]; pSegmentMaster[2]=pbsfThis->name[2]; pSegmentMaster[3]=pbsfThis->name[3]; pSegmentMaster[4]=pbsfThis->name[4]; pSegmentMaster[5]=pbsfThis->name[5]; pSegmentMaster[6]='\0'; */ /* see if Master Sequence was generated by VastSearch - Ken*/ if (JobID) { for (salpHead = psaAlignHead->data; salpHead; salpHead = salpHead->next) { oipMaster = ObjectIdNew(); oipMaster = GetObjectId(pbsaStruct->master, pSegmentMaster); sipMaster = ValNodeNew(NULL); sipMaster->choice = SEQID_LOCAL; sipMaster->data.ptrvalue = oipMaster; AssignLocaIdToSeqAlignMaster(sipMaster, salpHead); } } salpHead = psaAlignHead->data; /* from SeqAnnot to SeqAlign */ sepHead = sepHead->next; /* go to the slave sequences */ iCount1 = 0; while(pbsfThis){ pSegmentSlave = StringSave(&pbsfThis->name[7]); pSegmentSlave[6]='\0'; IdChainFound = FindIdSlave(pSegmentSlave, pbsaThis->features->features, iCount1); if(IdChainFound) iCount_ID++; iCount1++; MemFree(pSegmentSlave); pbsfThis = pbsfThis->next; } str = (Pointer) MemNew((size_t) ((iCount_ID + 1) * sizeof(Pointer))); for(iCount1 = 0; iCount1 < iCount_ID; iCount1++){ str[iCount1] = (Local_StringPtr) MemNew(sizeof(Local_String)); } pbsfThis = pbsfsThis->features; iCount_ID = 0; iCount1 = 0; while(pbsfThis){ pSegmentSlave = StringSave(&pbsfThis->name[7]); pSegmentSlave[6]='\0'; /* pSegmentSlave[0]=pbsfThis->name[7]; pSegmentSlave[1]=pbsfThis->name[8]; pSegmentSlave[2]=pbsfThis->name[9]; pSegmentSlave[3]=pbsfThis->name[10]; pSegmentSlave[4]=pbsfThis->name[11]; pSegmentSlave[5]=pbsfThis->name[12]; pSegmentSlave[6]='\0'; */ IdChainFound = FindIdSlave(pSegmentSlave, pbsaThis->features->features, iCount1); if(IdChainFound){ StringNCpy(str[iCount_ID]->str, pSegmentSlave, 4); str[iCount_ID]->str[4] = ' '; str[iCount_ID]->str[5] = pSegmentSlave[4]; str[iCount_ID]->str[6] = ' '; str[iCount_ID]->str[7] = pSegmentSlave[5]; str[iCount_ID]->str[8] = '\0'; AlignId = (Int2) (pbsfThis->id % 10) ; /* clique number */ sprintf(AlignIdStr, "%d", AlignId); str[iCount_ID]->str[8] = ' '; str[iCount_ID]->str[9] = '\0'; StringCat(str[iCount_ID]->str, AlignIdStr); sip_cpy = MakeLocalId(str[iCount_ID]->str); iCount_ID++; /* oip = ObjectIdNew(); oip->str = str; sip = ValNodeNew(NULL); sip->choice = SEQID_LOCAL; sip->data.ptrvalue = oip; sip_cpy = AsnIoMemCopy(sip, (AsnReadFunc) SeqIdAsnRead, (AsnWriteFunc) SeqIdAsnWrite); */ StringNCpy(PDBName, pSegmentSlave, 4); Chain = pSegmentSlave[4]; AssignLocaIdToBiostruc(sip_cpy, PDBName, Chain, pbsSlaveHead); AssignLocaIdToBioseq(sip_cpy, PDBName, Chain, sepHead); AssignLocaIdToSeqAlign(sip_cpy, PDBName, Chain, salpHead); } MemFree(pSegmentSlave); pbsfThis = pbsfThis->next; iCount1++; if(pbsSlaveHead) pbsSlaveHead = pbsSlaveHead->next; if(sepHead) sepHead = sepHead->next; if(salpHead) salpHead = salpHead->next; } return (pvnNcbi); }
/***************************************************************************** * * PrintTemplateSetPtr PrintTemplateSetLoad() * loads PrintTemplates * If path== NULL, looks for "prt.prt" in the "data" directory * *****************************************************************************/ static Boolean PrintTemplateSetLoadInt ( CharPtr path, Boolean verbose ) { AsnIoPtr aip; FILE *f; Boolean retval; Char filename [80]; Char fullpath [PATH_MAX]; CharPtr ptr; ErrSev lastLevel; aip = NULL; if (path != NULL && *path != '\0' && StringRChr (path, DIRDELIMCHR) != NULL) { StringNCpy (fullpath, path, sizeof (fullpath) - 1); if ((aip = AsnIoOpen (fullpath, "r")) == NULL) { if (verbose) { ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", fullpath); } return FALSE; } } else { if (path != NULL && *path != '\0') { StringNCpy (filename, path, sizeof (filename) - 1); } else { StringCpy (filename, "prt.prt"); } ProgramPath (fullpath, sizeof (fullpath) - 1); ptr = StringRChr (fullpath, DIRDELIMCHR); if (ptr != NULL) { *ptr = '\0'; } FileBuildPath (fullpath, NULL, filename); /* silence SEV_INFO errors from FileOpen() */ if ((lastLevel = ErrGetMessageLevel()) < SEV_WARNING) ErrSetMessageLevel (SEV_WARNING); if ((f = FileOpen (fullpath, "r")) == NULL) { ErrSetMessageLevel (lastLevel); if (FindPath ("NCBI", "NCBI", "DATA", fullpath, sizeof (fullpath) - 1)) { FileBuildPath (fullpath, NULL, filename); if ((aip = AsnIoOpen (fullpath, "r")) == NULL) { if (verbose) { ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", fullpath); } return FALSE; } } else { if (verbose) { ErrPost(CTX_NCBIOBJ, 1, "FindPath failed in PrintTemplateSetLoad - ncbi configuration file missing or incorrect"); } return FALSE; } } else { ErrSetMessageLevel (lastLevel); FileClose (f); if ((aip = AsnIoOpen(fullpath, "r")) == NULL) { if (verbose) { ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", fullpath); } return FALSE; } } } retval = PrintTemplateSetAsnRead(aip); AsnIoClose(aip); return retval; }
static void PrintSequence (BioseqPtr bsp, SeqFeatPtr sfp, FILE *fp, Boolean is_na) { Char buffer [255]; Uint1 code; Int2 count; Uint1 repr; Uint1 residue; SeqPortPtr spp; CharPtr title; CharPtr tmp; if (bsp != NULL && fp != NULL) { if ((Boolean) ISA_na (bsp->mol) == is_na) { repr = Bioseq_repr (bsp); if (repr == Seq_repr_raw || repr == Seq_repr_const) { title = BioseqGetTitle (bsp); tmp = StringMove (buffer, ">"); tmp = SeqIdPrint (bsp->id, tmp, PRINTID_FASTA_LONG); tmp = StringMove (tmp, " "); StringNCpy (tmp, title, 200); fprintf (fp, "%s\n", buffer); if (pmon != NULL) MonitorStrValue(pmon, buffer); if (is_na) { code = Seq_code_iupacna; } else { code = Seq_code_iupacaa; } if (sfp != NULL) { spp = SeqPortNewByLoc (sfp->location, code); } else { spp = SeqPortNew (bsp, 0, -1, 0, code); } if (spp != NULL) { count = 0; while ((residue = SeqPortGetResidue (spp)) != SEQPORT_EOF) { if (! IS_residue (residue)) { buffer [count] = '\0'; fprintf (fp, "%s\n", buffer); count = 0; switch (residue) { case SEQPORT_VIRT : fprintf (fp, "[Gap]\n"); break; case SEQPORT_EOS : fprintf (fp, "[EOS]\n"); break; default : fprintf (fp, "[Invalid Residue]\n"); break; } } else { buffer [count] = residue; count++; if (count >= CHARSPERLINE) { buffer [count] = '\0'; fprintf (fp, "%s\n", buffer); count = 0; } } } if (count != 0) { buffer [count] = '\0'; fprintf (fp, "%s\n", buffer); } SeqPortFree (spp); } } } } }
/***************************************************************************** * * This is the main program. * It reads command line or initial dialogue arguments * It initializes parse trees, entrez * It makes a list of the relevant files to search * It then calls ProcessFileList to open each file and process it * *****************************************************************************/ Int2 Main (void) { Char div [8]; FileListPtr flp = NULL; FILE *fp; Int2 i; Boolean is_network, did_init=FALSE; FileListPtr next; CharPtr outputfile; if (! GetArgs ("CdScan", NUMARGS, myargs)) /* get input args */ goto ret; /* process input args */ if (myargs[0].intvalue == 1) is_na = TRUE; /* scan nucleic acids */ else is_na = FALSE; /* scan proteins */ format = (Int2)(myargs[1].intvalue); is_custom = (Boolean)(myargs[2].intvalue); if (myargs[3].intvalue) /* show progress */ { pmon = MonitorStrNew("CdScan", 40); } outputfile = myargs[4].strvalue; /* output file name */ if (pmon != NULL) MonitorStrValue(pmon, "Reading Parse Trees"); if (! SeqEntryLoad() || ! SubmitAsnLoad()) /* read ASN.1 parse trees */ { Message(MSG_ERROR, "Can't open parse trees"); goto ret; } if (! PrintTemplateSetLoad ("asn2ff.prt")) { Message(MSG_ERROR, "Can't load print templates"); goto ret; } if (pmon != NULL) MonitorStrValue(pmon, "Initializing Entrez"); if (! EntrezInit ("cdscan", FALSE, &is_network)) /* init Entrez */ { Message(MSG_ERROR, "Can't initialize Entrez"); goto ret; } did_init = TRUE; if (is_network) { Message (MSG_ERROR, "Network service does not allow scanning"); goto ret; } if (pmon != NULL) MonitorStrValue(pmon, "Building File List"); eip = EntrezGetInfo (); /* set up the file lists */ if ((eip == NULL) || (eip->div_info == NULL)) { Message(MSG_ERROR, "Can't find Entrez file info"); goto ret; } flp = FileListNew (NULL, INT2_MIN, NULL, NULL); if (flp == NULL) { Message(MSG_ERROR, "Can't allocate file list"); goto ret; } div_info = eip->div_info; for (i = 0; i < eip->div_count; i++) { StringNCpy (div, div_info [i].tag, sizeof (div) - 1); if (! is_na) { CdEnumFiles (CdDir_rec, TYP_AA, div, EnumerateFiles, &flp); } else { CdEnumFiles (CdDir_rec, TYP_NT, div, EnumerateFiles, &flp); } } fp = FileOpen (outputfile, "w"); /* test that we can open output file */ if (fp == NULL) { Message(MSG_ERROR, "Can't open [%s]", outputfile); goto ret; } FileClose (fp); /* will be reopened for each input file */ ProcessFileList (flp, outputfile); /* process the file list */ ret: /* clean up */ if (pmon != NULL) /* close the progress monitor */ MonitorFree(pmon); if (did_init) EntrezFini(); /* close entrez */ while (flp != NULL) /* free file list */ { next = flp->next; MemFree (flp->fdir); MemFree (flp->fname); MemFree (flp); flp = next; } return 0; }
/******************************************************************** * * print_label_to_buffer_all_ex(buf, label, pos, strand, extra_space) * * print a label (with label_name=label, position=pos, * orientation = strand, extra_space = extra_space for partial start) * into the current buffer * return the offset of the buffer pointer to the current buffer * Has an option to strip/not-strip semicolons for hardline old blast * users. * *********************************************************************/ NLM_EXTERN Int4 print_label_to_buffer_all_ex(CharPtr buf, CharPtr label, Int4 pos, Uint1 strand, Boolean extra_space, Boolean is_html, Int4 label_space, Int4 num_space, Boolean show_strand, Boolean strip_semicolon) { Int4 len; Char symbol; Char temp[100]; Int4 i = 0; CharPtr str; Int4 max_b_space; /* * print the label to the buffer */ max_b_space = label_space + 1; len = 0; if(label) { if (strip_semicolon) { str= StrTok(label, ":"); if(str == NULL) str = label; else { str = StrTok(NULL, ":"); if(str == NULL) str = label; } } else { str = label; } len = MIN(max_b_space-1, (Int4)StringLen(str)); StringNCpy(buf, str, len); i = len; if(is_html) { sprintf(buf+i, "</a>"); i += 4; } buf[i++] = ' '; ++len; } /*add the leftover empty space */ for(; len<max_b_space; ++len) buf[i++] = ' '; if(show_strand) { symbol = ' '; if(strand == Seq_strand_plus) symbol = '>'; if(strand == Seq_strand_minus) symbol = '<'; buf[i++] = ' '; buf[i++] = symbol; buf[i++] = ' '; } len = 0; if(pos != -1) { sprintf(buf+i, "%ld", (long) pos); sprintf(temp, "%ld", (long) pos); len = StringLen(temp); i += len; } if(extra_space) /*for partial codon*/ ++len; max_b_space = num_space + 1; for(; len <max_b_space; ++len) buf[i++] = ' '; return i; }
static void Cn3D_ExportKin(IteM i) { PDNMS pdnmsThis = NULL; PMSD pmsdThis = NULL; Char pcSavestr[60]; Char pcSavename[32]; CharPtr Cn3D_pcKinName; GrouP g, g2, g3, g4; GrouP gMS; ButtoN b; Int2 iCount; if (Cn3D_Export_InUse) return; else Cn3D_Export_InUse = TRUE; pdnmsThis = GetSelectedModelstruc(); if (!pdnmsThis) { Cn3D_Export_InUse = FALSE; return; } pmsdThis = (PMSD) pdnmsThis->data.ptrvalue; Cn3D_wKinSave = ModalWindow(-20, -13, -10, -10, NULL); /* set up a group encolosing structures - models selection lists and - "info strings" */ Cn3D_pcKinName = StringSave(GetStrucStrings(pdnmsThis, PDB_ACC)); sprintf(pcSavestr, "Save %s As a Kinemage Rendered File ...", Cn3D_pcKinName); g = HiddenGroup(Cn3D_wKinSave, 0, 5, NULL); SetGroupMargins(g, 10, 10); SetGroupSpacing(g, 10, 5); StaticPrompt(g, pcSavestr, 0, 0, systemFont, 'l'); g2 = HiddenGroup(g, 2, 0, NULL); SetGroupMargins(g2, 10, 10); SetGroupSpacing(g2, 10, 5); StringNCpy(pcSavename, Cn3D_pcKinName, 8); StringCat(pcSavename, ".kin"); Cn3D_tKinSave = DialogText(g2, pcSavename, 18, (TxtActnProc) Cn3D_KinEnableProc); MemFree(Cn3D_pcKinName); Cn3D_bKinBrowse = PushButton(g2, " browse...", (BtnActnProc) Cn3D_KinBrowseProc); g3 = HiddenGroup(g, 2, 0, NULL); gMS = Cn3D_ModelSelect(g3, FALSE); /* no vector models for Kin files saves */ g4 = HiddenGroup(g3, 0, 2, NULL); SetGroupMargins(g4, 10, 10); SetGroupSpacing(g4, 10, 5); Cn3D_bKinOk = PushButton(g4, "OK", Cn3D_ExportKinNow); b = PushButton(g4, "Cancel", Cn3D_CancelKin); Cn3D_gColorAtoms = NormalGroup(g, 2, 2, " color by...", systemFont, NULL); SetGroupMargins(Cn3D_gColorAtoms, 10, 10); SetGroupSpacing(Cn3D_gColorAtoms, 10, 5); RadioButton(Cn3D_gColorAtoms, "Molecule number"); RadioButton(Cn3D_gColorAtoms, "Secondary Structure & Residue Type"); RadioButton(Cn3D_gColorAtoms, "Thermal Factors"); RadioButton(Cn3D_gColorAtoms, "Element"); SetValue(Cn3D_gColorAtoms, 1); Cn3D_gRenderOpts = NormalGroup(g, 2, 3, " viewable subsets...", systemFont, NULL); Cn3D_bRender[0] = CheckBox(Cn3D_gRenderOpts, "Virtual Backbone", NULL); Cn3D_bRender[1] = CheckBox(Cn3D_gRenderOpts, "Real Backbone", NULL); Cn3D_bRender[2] = CheckBox(Cn3D_gRenderOpts, "Residues", NULL); Cn3D_bRender[3] = CheckBox(Cn3D_gRenderOpts, "Heterogens", NULL); Cn3D_bRender[4] = CheckBox(Cn3D_gRenderOpts, "Alternate Conformations", NULL); Cn3D_bRender[5] = CheckBox(Cn3D_gRenderOpts, "NMR Animations", NULL); for (iCount = 0; iCount < 6; iCount++) SetStatus(Cn3D_bRender[iCount], TRUE); Cn3D_KinEnableProc(NULL); Select(Cn3D_bKinOk); /* disable appropriate stuff here */ Cn3D_DisableFileOps(); Show(Cn3D_wKinSave); return; }
void BioseqRawToRaw(BioseqPtr bsp, Boolean idonly, short whichSeq, short *seqnum, char **seq, char **seqid, long *seqlen) { SeqPortPtr spp; SeqIdPtr bestid; Uint1 repr, code, residue; CharPtr tmp, title; long outlen, outmax; char localid[256], *sp; /* !!! this may be called several times for a single sequence because SeqEntryExplore looks for parts and joins them... assume seq, seqid, seqlen may contain data (or NULL) */ if (bsp == NULL) return; repr = Bioseq_repr(bsp); if (!(repr == Seq_repr_raw || repr == Seq_repr_const)) return; (*seqnum)++; if (!(whichSeq == *seqnum || whichSeq == 0)) return; bestid = SeqIdFindBest(bsp->id, (Uint1) 0); title = BioseqGetTitle(bsp); if (idonly) { sprintf(localid, " %d) ", *seqnum); tmp= localid + strlen(localid)-1; } else { strcpy(localid," "); tmp= localid; } tmp = SeqIdPrint(bestid, tmp, PRINTID_FASTA_SHORT); tmp = StringMove(tmp, " "); StringNCpy(tmp, title, 200); /* fprintf(stderr,"BioseqRawToRaw: localid='%s'\n",localid); */ /* < seqid is fixed storage */ /* strcpy( *seqid, localid); */ /* < seqid is variable sized */ outmax= strlen(localid) + 3; if (*seqid==NULL) { *seqid= (char*) malloc(outmax); if (*seqid==NULL) return; strcpy(*seqid, localid); } else { outmax += strlen(*seqid) + 2; *seqid= (char*) realloc( *seqid, outmax); if (*seqid==NULL) return; if (!idonly) strcat(*seqid, "; "); strcat(*seqid, localid); } if (idonly) { strcat(*seqid,"\n"); return; } if (ISA_na(bsp->mol)) code = Seq_code_iupacna; else code = Seq_code_iupacaa; spp = SeqPortNew(bsp, 0, -1, 0, code); SeqPortSeek(spp, 0, SEEK_SET); sp= *seq; if (sp==NULL) { /* this is always true now !? */ outlen= 0; outmax= 500; sp= (char*) malloc(outmax); } else { outlen= strlen(sp); outmax= outlen + 500; sp= (char*) realloc( sp, outmax); } if (sp==NULL) return; while ((residue = SeqPortGetResidue(spp)) != SEQPORT_EOF) { if (outlen>=outmax) { outmax= outlen + 500; sp= (char*) realloc(sp, outmax); if (sp==NULL) return; } sp[outlen++] = residue; } sp= (char*) realloc(sp, outlen+1); if (sp!=NULL) sp[outlen]= '\0'; *seq= sp; *seqlen= outlen; SeqPortFree(spp); return; }
Int2 Main (void) { Int2 m_argModuleIn=0, f_arg_moduleOut=1, X_argDTDModuleOut=2, T_argTreeDumpOut=3, v_argPrintFileIn = 4, p_argPrintFileOut = 5, x_argXMLDataOut=6, d_argBinaryFileIn = 7 , t_argAsnTypeName = 8, e_argBinaryFileOut = 9 , o_argHeadFile = 10, l_argLoadFile = 11 , b_argBufferSize = 12, w_argTokenMax = 13 /*--- args below here are capitilized and for code generation, only--*/ /*-- Except for the 'M' arg, which will also affect normal use ---*/ , G_argGenerateCode = 14, M_argMoreModuleFiles = 15 , B_argCodeFileName = 16, D_argCodeGenDebugLevel = 17 , S_argDebugFileName = 18, I_argExtraIncludeName = 19 , Z_argBitTwiddle = 20, K_argLoadName = 21 , J_objMgrEntry = 22, L_objMgrLabel = 23, P_argXMLmodulePrefix = 24 , V_argChoiceStruct = 25; AsnIoPtr aip = NULL, aipout = NULL, xaipout = NULL, aipencode = NULL; FILE * fp; AsnModulePtr amp = NULL, currentmod = NULL, nextmod, thisamp; AsnTypePtr atp; Boolean print_each_module = FALSE; AsnCodeInfoPtr acip = (AsnCodeInfoPtr)MemNew(sizeof(AsnCodeInfo)); CharPtr filename = NULL, p, last_comma, objmgrentry = NULL; int len; /* never abort on error, but show it */ ErrSetFatalLevel(SEV_MAX); ErrSetMessageLevel(SEV_MIN); asnargs[P_argXMLmodulePrefix].defaultvalue = (const char *)AsnGetXMLmodulePrefix(); if (! GetArgs("AsnTool 4", NUMARGS, asnargs)) return 1; ErrClear(); AsnSetXMLmodulePrefix((CharPtr)(asnargs[P_argXMLmodulePrefix].strvalue)); /* if (! GetArgs("AsnTool 4", NUMARGS, asnargs)) return 1; ErrClear(); */ if (! AsnIoSetBufsize(NULL, (Int2)asnargs[b_argBufferSize].intvalue)) return 1; if ((aip = AsnIoOpen(asnargs[m_argModuleIn].strvalue, "r")) == NULL) { ErrShow(); return 1; } acip -> loadname = asnargs[m_argModuleIn].strvalue; if (asnargs[K_argLoadName].strvalue != NULL) { acip -> loadname = asnargs[K_argLoadName].strvalue; /* overrides m_argModuleIn, if set */ } if (asnargs[e_argBinaryFileOut].strvalue != NULL) /* output a binary value file */ if ((aipencode = AsnIoOpen(asnargs[e_argBinaryFileOut].strvalue, "wb")) == NULL) { ErrShow(); return 1; } /** parse the module(s) ***/ if (asnargs[f_arg_moduleOut].strvalue != NULL) { if ((aipout = AsnIoOpen(asnargs[f_arg_moduleOut].strvalue, "w")) == NULL) { ErrShow(); return 1; } } thisamp = NULL; while ((nextmod = AsnLexTReadModule(aip)) != NULL ) { if (thisamp == NULL) thisamp = nextmod; if (amp == NULL) amp = nextmod; else currentmod->next = nextmod; currentmod = nextmod; } acip -> last_amp = currentmod; /* last module of main file */ AsnStoreTree(acip->loadname, thisamp); /* store and link tree */ /*--- read additional module files that will be used for everything but code generation. ---*/ if (asnargs[M_argMoreModuleFiles].strvalue != NULL) for (p = asnargs[M_argMoreModuleFiles].strvalue; *p; p = last_comma + 1) { /*--- extract next filename for reading ASN.1 definitions ---*/ for (last_comma = p; *last_comma; last_comma++) { if (*last_comma == ',') break; } len = last_comma - p; filename = (char *)MemFree (filename); filename = (char *)MemNew (len + 1); StringNCpy (filename, p, len); filename[len] = '\0'; #ifdef WIN_DUMB printf ("Loading %s \n", filename); #endif if ((aip = AsnIoOpen(filename, "r")) == NULL) { ErrShow(); return 1; } /*--- read the modules in this current file ---*/ thisamp = NULL; while ((nextmod = AsnLexTReadModule(aip)) != NULL ) { if (thisamp == NULL) thisamp = nextmod; if (amp == NULL) amp = nextmod; else currentmod->next = nextmod; currentmod = nextmod; } AsnStoreTree(filename, thisamp); /* store and link tree */ if (!*last_comma) break; aip = AsnIoClose(aip); } aip = AsnIoClose(aip); if (amp == NULL) { ErrPostEx(SEV_FATAL,0,0, "Unable to continue due to bad ASN.1 module"); ErrShow(); return 1; } if (asnargs[f_arg_moduleOut].strvalue != NULL) { if ((aipout = AsnIoOpen(asnargs[f_arg_moduleOut].strvalue, "w")) == NULL) { ErrShow(); return 1; } currentmod = amp; do { AsnPrintModule(currentmod, aipout); if (currentmod == acip->last_amp) /* last main module */ currentmod = NULL; else currentmod = currentmod->next; } while (currentmod != NULL); aipout = AsnIoClose(aipout); } if (asnargs[X_argDTDModuleOut].strvalue != NULL) { Char tbuf[250]; CharPtr ptr; if (! StringCmp(asnargs[X_argDTDModuleOut].strvalue, "m")) { print_each_module = TRUE; } else { if ((aipout = AsnIoOpen(asnargs[X_argDTDModuleOut].strvalue, "wx")) == NULL) { ErrShow(); return 1; } } currentmod = amp; do { if (print_each_module) { StringMove(tbuf, currentmod->modulename); for (ptr = tbuf; *ptr != '\0'; ptr++) { if (*ptr == '-') *ptr = '_'; } StringMove(ptr, ".dtd"); AsnPrintModuleXMLInc(currentmod, tbuf); StringMove(ptr, ".mod"); aipout = AsnIoOpen(tbuf, "wx"); } AsnPrintModuleXML(currentmod, aipout); if (print_each_module) aipout = AsnIoClose(aipout); if (currentmod == acip->last_amp) /* last main module */ currentmod = NULL; else currentmod = currentmod->next; } while (currentmod != NULL); if (! print_each_module) aipout = AsnIoClose(aipout); } if (asnargs[T_argTreeDumpOut].strvalue != NULL) { if ((fp = FileOpen(asnargs[T_argTreeDumpOut].strvalue, "w")) == NULL) { ErrShow(); return 1; } currentmod = amp; do { AsnPrintTreeModule(currentmod, fp); if (currentmod == acip->last_amp) /* last main module */ currentmod = NULL; else currentmod = currentmod->next; } while (currentmod != NULL); FileClose(fp); } acip -> amp = amp; /* print a value file */ if (asnargs[p_argPrintFileOut].strvalue != NULL) { if ((aipout = AsnIoOpen(asnargs[p_argPrintFileOut].strvalue, "w")) == NULL) { ErrShow(); return 1; } } /* print an XML file */ if (asnargs[x_argXMLDataOut].strvalue != NULL) { if ((xaipout = AsnIoOpen(asnargs[x_argXMLDataOut].strvalue, "wx")) == NULL) { ErrShow(); return 1; } } if (asnargs[v_argPrintFileIn].strvalue != NULL) /* read a printvalue file */ { if ((aip = AsnIoOpen(asnargs[v_argPrintFileIn].strvalue, "r")) == NULL) { ErrShow(); return 1; } AsnTxtReadValFile(amp, aip, aipout, aipencode, xaipout); ErrShow(); } aip = AsnIoClose(aip); if (asnargs[d_argBinaryFileIn].strvalue != NULL) /* read a ber file */ { if ((asnargs[t_argAsnTypeName].strvalue == NULL) || (! TO_UPPER(*asnargs[t_argAsnTypeName].strvalue))) { ErrPostEx(SEV_FATAL,0,0, "Must use -t Type to define contents of decode file"); ErrShow(); return 1; } atp = AsnTypeFind(amp, asnargs[t_argAsnTypeName].strvalue); if (atp == NULL) { #ifdef WIN_MSWIN ErrPostEx(SEV_FATAL,0,0, "Couldn't find Type %Fs", asnargs[t_argAsnTypeName].strvalue); #else ErrPostEx(SEV_FATAL,0,0, "Couldn't find Type %s", asnargs[t_argAsnTypeName].strvalue); #endif ErrShow(); return 1; } if ((aip = AsnIoOpen(asnargs[d_argBinaryFileIn].strvalue, "rb")) == NULL) { ErrShow(); return 1; } AsnBinReadValFile(atp, aip, aipout, aipencode, xaipout); ErrShow(); } AsnIoClose(xaipout); AsnIoClose(aipout); AsnIoClose(aip); AsnIoClose(aipencode); if (asnargs[o_argHeadFile].strvalue != NULL) /* produce header file */ AsnOutput(asnargs[o_argHeadFile].strvalue, amp, FALSE, (Int2)asnargs[w_argTokenMax].intvalue); if (asnargs[l_argLoadFile].strvalue != NULL) /* produce loader file */ AsnOutput(asnargs[l_argLoadFile].strvalue, amp, TRUE, (Int2)asnargs[w_argTokenMax].intvalue); if (asnargs[G_argGenerateCode ].intvalue != 0) { acip -> filename = asnargs[B_argCodeFileName].strvalue; acip -> do_bit_twiddle = asnargs[Z_argBitTwiddle].intvalue; acip -> force_choice_struct = asnargs[V_argChoiceStruct].intvalue; acip -> include_filename = asnargs[I_argExtraIncludeName].strvalue; acip -> maxDefineLength = asnargs[w_argTokenMax].intvalue; acip -> debug_level = asnargs[D_argCodeGenDebugLevel ].intvalue; acip -> object_manager_entry = asnargs[J_objMgrEntry].strvalue; acip -> object_label = asnargs[L_objMgrLabel].strvalue; if (asnargs[S_argDebugFileName].strvalue != NULL) { (acip -> bug_fp) = FileOpen (asnargs[S_argDebugFileName].strvalue, "w"); } else { (acip -> bug_fp) = FileOpen ("stderr", "w"); } AsnCode(acip); } MemFree(acip); MemFree(filename); return 0; }