static int mfmt_close_output( void *handle ) { /* Irregardless of how we started it - close it */ if( asn_hand->count > 0 ) AsnEndStruct( asn_hand->ioptr, PUB_SET_medline); switch( asn_hand->open_state ) { case init_output: AsnIoFlush( asn_hand->ioptr ); /* This trick is to fool AsnIoClose() */ asn_hand->ioptr->fp = fopen( "/dev/null", "w" ); /* Drop through */ case open_output: AsnIoClose( asn_hand->ioptr ); case not_open: default: ; /* Do nothing - it is not open */ } /* Reinitialize the record */ asn_hand->file = NULL; asn_hand->have_error = FALSE; asn_hand->ioptr = NULL; asn_hand->open_state = not_open; /* We always assume success */ return( True ); }
static void SaveSetDescriptors (SeqDescrPtr sdp, Pointer userdata) { SaveSetSdpPtr sp; MolInfoPtr mip; if (sdp == NULL || userdata == NULL) return; if (sdp->choice != Seq_descr_source && sdp->choice != Seq_descr_pub && sdp->choice != Seq_descr_molinfo && sdp->choice != Seq_descr_comment) return; sp = (SaveSetSdpPtr) userdata; if (sdp->choice == Seq_descr_molinfo && (mip = (MolInfoPtr) sdp->data.ptrvalue) != NULL) { if (mip->biomol == MOLECULE_TYPE_PEPTIDE || sp->already_have_molinfo) { return; } else { sp->already_have_molinfo = TRUE; } } SeqDescAsnWrite (sdp, sp->aip, NULL); AsnPrintNewLine (sp->aip); AsnIoFlush (sp->aip); }
static void SaveSeqLocEntity (Uint2 entityID, SelectedSavePtr ssp) { ObjMgrDataPtr omdp; ObjMgrTypePtr omtp; if (entityID == 0 || ssp == NULL) { return; } omdp = ObjMgrGetDataStruct (ssp->omp, entityID); if (omdp == NULL) return; if (omdp->choicetype == OBJ_SEQENTRY || omdp->datatype != OBJ_SEQLOC) { return; /* not seqloc */ } omtp = ObjMgrTypeFind(ssp->omp, OBJ_SEQLOC, NULL, NULL); if (omtp == NULL) { ErrPostEx(SEV_ERROR,0,0,"Can't locate type record for [%d]", (int)OBJ_SEQLOC); return; } (*(omtp->asnwrite))(omdp->dataptr, ssp->aip, NULL); AsnPrintNewLine (ssp->aip); AsnIoFlush (ssp->aip); }
static Boolean SaveOneSelectedItem (GatherObjectPtr gop) { SelectedSavePtr ssp; SelStructPtr sel; ObjMgrTypePtr omtp; if (gop == NULL || gop->dataptr == NULL) return TRUE; ssp = (SelectedSavePtr) gop->userdata; if (ssp == NULL || ssp->aip == NULL || ssp->ssp == NULL) return TRUE; sel = ssp->ssp; while (sel != NULL && (sel->entityID != gop->entityID || sel->itemtype != gop->itemtype || sel->itemID != gop->itemID)) { sel = sel->next; } if (sel == NULL) return TRUE; omtp = ObjMgrTypeFind(ssp->omp, sel->itemtype, NULL, NULL); if (omtp == NULL) { ErrPostEx(SEV_ERROR,0,0,"Can't locate type record for [%d]", (int)sel->itemtype); return TRUE; } (*(omtp->asnwrite))(gop->dataptr, ssp->aip, NULL); AsnPrintNewLine (ssp->aip); AsnIoFlush (ssp->aip); return TRUE; }
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; }
Int2 Main(void) { AsnIoPtr aip; SeqEntryPtr sep; BytePtr buf; Uint2 size = 32000, count; AsnIoMemPtr aimp; /* check command line arguments */ if ( ! GetArgs("testmem",NUMARG, myargs)) return 1; /* load the sequence alphabets */ /* (and sequence parse trees) */ if (! SeqEntryLoad()) ErrShow(); /* open the ASN.1 input file in the right mode */ if ((aip = AsnIoOpen (myargs[0].strvalue, myargs[1].intvalue?"rb":"r")) == NULL) ErrShow(); sep = SeqEntryAsnRead(aip, NULL); /* read the entry */ AsnIoClose(aip); SeqEntryPack(sep); /* pack it */ buf = MemNew(size); /* allocate a buffer */ aimp = AsnIoMemOpen("wb", buf, size); /* open to write asn1 to it */ SeqEntryAsnWrite(sep, aimp->aip, NULL); /* write it */ AsnIoFlush(aimp->aip); /* flush it */ count = aimp->count; /* record how many bytes in it */ AsnIoMemClose(aimp); /* close it */ SeqEntryFree(sep); /* release the object */ aimp = AsnIoMemOpen("rb", buf, count); /* open to read from buffer */ sep = SeqEntryAsnRead(aimp->aip, NULL); /* read it */ AsnIoMemClose(aimp); /* close it */ MemFree(buf); /* free the buffer */ /* open the output file */ aip = AsnIoOpen (myargs[2].strvalue, "w"); SeqEntryAsnWrite(sep, aip, NULL); /* print it */ AsnIoClose(aip); SeqEntryFree(sep); return(0); }
static void WriteOneSubmission ( CharPtr path, SeqSubmitPtr ssp ) { AsnIoPtr aip; aip = AsnIoOpen (path, "w"); if (aip == NULL) return; SeqSubmitAsnWrite (ssp, aip, NULL); AsnIoFlush (aip); AsnIoClose (aip); }
static void WriteOneFile ( OutputStreamPtr osp, SeqEntryPtr sep ) { AsnIoPtr aip; aip = AsnIoFromOutputStream (osp); if (aip != NULL) { SeqEntryAsnWrite (sep, aip, NULL); AsnIoFlush (aip); } if (aip != osp->aip) { AsnIoClose (aip); } }
static void WriteOneFile ( CharPtr directory, CharPtr base, CharPtr suffix, SeqEntryPtr sep ) { AsnIoPtr aip; Char file [FILENAME_MAX], path [PATH_MAX]; StringNCpy_0 (path, directory, sizeof (path)); sprintf (file, "%s.%s", base, suffix); FileBuildPath (path, NULL, file); aip = AsnIoOpen (path, "w"); if (aip == NULL) return; SeqEntryAsnWrite (sep, aip, NULL); AsnIoFlush (aip); AsnIoClose (aip); }
Int2 Main(void) { Char app [64]; CharPtr directory; CharPtr ptr; Char sfx [32]; OutputStreamData osd; InputStreamData isd; AsnStreamData asd; Int4 gap_sizes[2]; Int4 rval = 0; Int4 u_eq = 0, u_gteq = -1, k_eq = 0, k_gteq = -1; /* 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; } SetUpAsnStreamData (&asd); /* initialize OuputStreamData */ MemSet (&osd, 0, sizeof (osd)); /* initialize InputStreamData */ MemSet (&isd, 0, sizeof (isd)); /* initialize gap_sizes */ gap_sizes[0] = 0; gap_sizes[1] = 0; /* process command line arguments */ sprintf (app, "raw2delt %s", RAW2DELT_APPLICATION); if (! GetArgs (app, sizeof (myargs) / sizeof (Args), myargs)) { return 0; } u_eq = (Int4) myargs [u_argEqUnknownGap].intvalue; u_gteq = (Int4) myargs [U_argGTEqUnknownGap].intvalue; k_eq = (Int4) myargs [k_argEqUnknownGap].intvalue; k_gteq = (Int4) myargs [K_argGtEqUnknownGap].intvalue; if (u_eq < 1 && u_gteq < 1 && k_eq < 1 && k_gteq < 1) { Message (MSG_FATAL, "Must specify values for at least one of -u, -U, -k, -K"); return 1; } else if (u_eq > -1 && u_gteq > -1) { Message (MSG_FATAL, "May only specify value for -u or -U, not both"); return 1; } else if (k_eq > -1 && k_gteq > -1) { Message (MSG_FATAL, "May only specify value for -k or -K, not both"); return 1; } if (u_eq > 0) { gap_sizes[0] = u_eq; } else if (u_gteq > 0) { gap_sizes[0] = 0 - u_gteq; } if (k_eq > 0) { gap_sizes[1] = k_eq; } else if (k_gteq > 0) { gap_sizes[1] = 0 - k_gteq; } if (gap_sizes[0] == gap_sizes[1]) { Message (MSG_FATAL, "Cannot specify the same size for known and unknown length gaps"); return 1; } directory = (CharPtr) myargs [p_argInputPath].strvalue; osd.results_dir = (CharPtr) myargs [r_argOutputPath].strvalue; if (StringHasNoText (osd.results_dir)) { osd.results_dir = NULL; } osd.suffix = (CharPtr) myargs [x_argSuffix].strvalue; osd.outsuffix = (CharPtr) myargs [s_argOutSuffix].strvalue; osd.base = (CharPtr) myargs [i_argInputFile].strvalue; osd.outfile = (CharPtr) myargs [o_argOutputFile].strvalue; if (StringHasNoText (osd.outfile)) { osd.outfile = NULL; } osd.is_binary = (Boolean) myargs [d_argOutputBinary].intvalue; if (osd.base == "stdin") { osd.base = NULL; } /* if we don't have an output directory or an output file, and the user hasn't provided an * output suffix, add a default. */ if (osd.results_dir == NULL && osd.outfile == NULL && StringHasNoText (osd.outsuffix)) { osd.outsuffix = ".delta"; } isd.is_binary = (Boolean) myargs [b_argInputBinary].intvalue; isd.is_seqentry = (Boolean) myargs [e_argInputSeqEntry].intvalue; isd.directory = directory; isd.base = osd.base; isd.suffix = osd.suffix; if (StringDoesHaveText (osd.outfile)) { osd.aip = AsnIoOpen (osd.outfile, "w"); if (osd.aip == NULL) { Message (MSG_FATAL, "Unable to open output file"); return 1; } } else { if (StringHasNoText (osd.results_dir)) { osd.results_dir = directory; } /* if we're putting the results in a separate directory, strip the directory name from the output base */ if (!StringHasNoText (osd.results_dir) && !StringHasNoText (osd.base)) { #ifdef OS_MSWIN ptr = StringRChr (osd.base, '\\'); #else ptr = StringRChr (osd.base, '/'); #endif; if (ptr != NULL) { osd.base = ptr + 1; } } } if (StringHasNoText(directory) && StringHasNoText(osd.base)) { rval = ProcessStream (&isd, &osd, &asd, gap_sizes); } else if (StringDoesHaveText (osd.base)) { ptr = StringRChr (osd.base, '.'); sfx[0] = '\0'; if (ptr != NULL) { StringNCpy_0 (sfx, ptr, sizeof (sfx)); *ptr = '\0'; } osd.suffix = sfx; isd.suffix = sfx; if (isd.is_binary) { rval = ProcessStream (&isd, &osd, &asd, gap_sizes); } else { rval = ProcessOneRecord (directory, &osd, gap_sizes); } } else { rval = FileRecurse (directory, &isd, &osd, &asd, gap_sizes); } if (osd.aip != NULL) { AsnIoFlush (osd.aip); AsnIoClose (osd.aip); } return rval; }
BGenBankPtr BGenBankInit(void) { BGenBankPtr bgbp; AsnModulePtr amp; AsnTypePtr atp_bioseq_set; AsnTypePtr atp_bioseq_set_level; AsnTypePtr atp_bioseq_set_class; AsnTypePtr atp_bioseq_set_release; AsnTypePtr atp_bioseq_set_date; AsnTypePtr atp_bioseq_set_seq_set; AsnTypePtr atp_bioseq_set_seq_set_E; Char release[] = "Q-server Production"; Char date_time[128]; NCBI_Date date; DataVal dv; DateClean(&date); bgbp = (BGenBankPtr)MemNew(sizeof(BGenBank)); bgbp->aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL); amp = AsnAllModPtr(); MACRO_atp_find(atp_bioseq_set,Bioseq-set); MACRO_atp_find(atp_bioseq_set_level,Bioseq-set.level); MACRO_atp_find(atp_bioseq_set_class,Bioseq-set.class); MACRO_atp_find(atp_bioseq_set_release,Bioseq-set.release); MACRO_atp_find(atp_bioseq_set_date,Bioseq-set.date); MACRO_atp_find(atp_bioseq_set_seq_set,Bioseq-set.seq-set); MACRO_atp_find(atp_bioseq_set_seq_set_E,Bioseq-set.seq-set.E); if(!AsnOpenStruct(bgbp->aip,atp_bioseq_set,NULL)) return NULL; dv.intvalue = 0; if(!AsnWrite(bgbp->aip,atp_bioseq_set_level,&dv)) return NULL; dv.intvalue = 7; if(!AsnWrite(bgbp->aip,atp_bioseq_set_class,&dv)) return NULL; dv.ptrvalue = &release; if(!AsnWrite(bgbp->aip,atp_bioseq_set_release,&dv)) return NULL; Nlm_DayTimeStr(date_time,TRUE,TRUE); date.str=date_time; if(!DateAsnWrite(&date,bgbp->aip,atp_bioseq_set_date)) return NULL; if(!AsnOpenStruct(bgbp->aip,atp_bioseq_set_seq_set,NULL)) return NULL; AsnIoFlush(bgbp->aip); bgbp->atp =atp_bioseq_set_seq_set_E; bgbp->atp_bioseq_set_seq_set = atp_bioseq_set_seq_set; bgbp->atp_bioseq_set = atp_bioseq_set; return bgbp; }
Boolean LIBCALL VastToCn3D(WWWInfoPtr www_info) { FILE *pFile = NULL; FILE *pIn = NULL; Char pcBuf[100], pcLine[256], giBuf[20], URL[200]; CharPtr pcTest, pcL1 = NULL, Name, www_arg; Int4 GetGi, Fid, Fsid, iFileExists = 0, indx; BiostrucAnnotSetPtr pbsa = NULL; BiostrucAnnotSetPtr pbsaShort = NULL; BiostrucFeatureSetPtr pbsfs = NULL; BiostrucFeaturePtr pbsf = NULL; BiostrucResidueGraphSetPtr stdDictionary; ValNodePtr pvnFids = NULL, pvnFid = NULL; Int2 iTest = 0, iPDB = 0, iColor; AsnIoPtr aip = NULL; Byte bRender; Char *IPAddress = getenv("REMOTE_HOST"); Int4 NumLabels, iMMDBId; ValNode * pbsidThis; BiostrucPtr pbsMaster, pbsSlave, pbsSlaveHead = NULL, pbsSlaveTail, pbsTemp; Char szName[5], chain[2]; Char * szTemp; SeqAnnotPtr psaAlignHead = NULL, psaAlignTail; SeqAlignPtr salpHead, salpTail; SeqIdPtr sip; DenseSegPtr dsp; BioseqPtr bsp; SeqEntryPtr sep; char str [52]; NcbiMimeAsn1Ptr pvnNcbi; BiostrucAlignPtr pbsaStruct; AsnIoPtr paiFile, aipr; Boolean is_network; Int4 uid, uidmaster = 0; Int2 retcode = 3; CharPtr JobID = NULL, pcPass; Char AsnPath[PATH_MAX]; Char AsnName[10]; Int2 ret, complexity; Int4 iFidCount = 0; Boolean Chain; /* SeqAsnLoad(); objmmdb1AsnLoad(); objmmdb2AsnLoad(); objmmdb3AsnLoad(); SeqAlignAsnLoad(); objmimeAsnLoad(); */ if ((indx = WWWFindName(www_info, "uid")) < 0) { printf("Content-type: text/html\n\n"); printf("<h3>No accession (PDB ID) was input - nothing to report.</h3>\n"); return 0; } www_arg = WWWGetValueByIndex(www_info, indx); if (isdigit(www_arg[0])) GetGi = (Int4) atoi(www_arg); else { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3>Non-numeric MMDB-id input - no results.</h3>\n"); return 0; } /* vsid and pass are to look at alignments from VAST Search */ if ((indx = WWWFindName(www_info, "vsid")) >= 0) { www_arg = WWWGetValueByIndex(www_info, indx); JobID = StringSave(www_arg); if ((indx = WWWFindName(www_info, "pass")) < 0) { printf("Content-type: text/html\n\n"); printf("<body bgcolor = \"#f0f0f0\">\n"); printf("<h2>VAST SEARCH</h2>\n"); printf("<h3>Password required.</h3>\n"); return 0; } else { www_arg = WWWGetValueByIndex(www_info, indx); pcPass = StringSave(www_arg); if ((ret = Check_VastSearch_Password(pcPass, JobID)) != 1) { if (ret == 2) return 0; printf("Content-type: text/html\n\n"); printf("<body bgcolor = \"#f0f0f0\">\n"); printf("<h2>VAST SEARCH</h2>\n"); printf("<h3>Incorrect password.</h3>\n"); return 0; } } } if ((indx = WWWFindName(www_info, "hit")) < 0) { printf("Content-type: text/html\n\n"); printf("<body bgcolor = \"#f0f0f0\">\n"); printf("<br>\n<h2>No alignment was selected!</h2>\n"); printf("<h3>Please click on up to 5 boxes in the leftmost column of the table.</h3>\n"); return 0; } /* loop over all the "hit" values in the list */ NumLabels = WWWGetNumEntries(www_info); for (indx = 0; indx < NumLabels; indx++) { Name = WWWGetNameByIndex(www_info, indx); if (StrICmp(Name, "hit") == 0) { www_arg = WWWGetValueByIndex(www_info, indx); if (isdigit(www_arg[0])) Fid = (Int4) atol(www_arg); else { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3>Non-numeric slave alignment code - no results.</h3>\n"); return 0; } if (++iFidCount > 5) break; pvnFid = ValNodeAddInt(&pvnFids, 0, Fid); } } if ((indx = WWWFindName(www_info, "chaindom")) < 0) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3>No feature set ID (master alignment code) - nothing to report.</h3>\n"); return 0; } www_arg = WWWGetValueByIndex(www_info, indx); if (isdigit(www_arg[0])) Fsid = (Int4) atoi(www_arg); else { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3>Non-numeric master alignment code - no results.</h3>\n"); return 0; } if ((indx = WWWFindName(www_info, "chn_complexity")) < 0) Chain = TRUE; else { www_arg = WWWGetValueByIndex(www_info, indx); complexity =(Int2)atoi(www_arg); if (complexity) Chain = TRUE; else Chain = FALSE; } if ((indx = WWWFindName(www_info, "atm_complexity")) < 0) /* select alpha Carbons only by default */ complexity = ONECOORDRES; else { www_arg = WWWGetValueByIndex(www_info, indx); if (isdigit(www_arg[0])) complexity = (Int2) atoi(www_arg); else complexity = ONECOORDRES; } if ((complexity != ONECOORDRES) && (complexity != ONECOORDATOM)) /* bizarre value, but default to alpha-Carbons only */ complexity = ONECOORDRES; /* action == 0 indicates MIME; action == 1 is text; action == 2 is save */ if ((indx = WWWFindName(www_info, "action")) < 0) iPDB = 0; else { www_arg = WWWGetValueByIndex(www_info, indx); if (isdigit(www_arg[0])) iPDB = (Int4) atoi(www_arg); else iPDB = 0; } if (VASTInit() != TRUE) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3>Can't find VAST data on server.\n"); printf("Contact [email protected]</h3>\n"); return 0; } OpenMMDBAPI((POWER_VIEW /* ^ FETCH_ENTREZ */), NULL); pbsa = LocalGetFeatureSet(GetGi, Fsid, JobID); if (pbsa == NULL) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3>No master alignment record exists for %ld.</h3>\n", (long) GetGi); return 0; } if (iFidCount == 1) pbsaShort = BiostrucAnnotSetGetByFid(pbsa, Fid, Fsid); else pbsaShort = PruneBiostrucAnnotHits(pbsa, Fsid, pvnFids); if (pbsaShort == NULL) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3>Can't find alignment record.</h3>\n"); return 0; } if (MMDBInit() == FALSE) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3>MMDBInit failed.</h3>\n"); return 0; } pbsfs = pbsaShort->features; pbsaStruct = BiostrucAlignNew(); if (pbsfs) { pbsf = pbsfs->features; szTemp = pbsf->name; szName[0] = szTemp[0]; szName[1] = szTemp[1]; szName[2] = szTemp[2]; szName[3] = szTemp[3]; szName[4] = '\0'; } if (JobID == NULL) pbsMaster = FetchBiostrucPDB(szName, complexity, 1); else { AsnName[0]='\0'; StringCpy(AsnName, "/b"); StringCat(AsnName, szName); AsnPath[0]='\0'; StringCpy(AsnPath, VSPATH); StringCat(AsnPath, JobID); StringCat(AsnPath, AsnName); pbsMaster = FetchBS(AsnPath, 0, complexity, 1, POWER_VIEW); } if (pbsMaster == NULL) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3> Unable to load master structure.</h3>\n"); return 0; } /* Load in Standard Dictionary to make sequences - Ken */ aipr = NULL; aipr = AsnIoOpen("bstdt", "rb"); if (aipr == NULL) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3>Can't find standard dictionary.</h3>\n"); return 0; } stdDictionary = BiostrucResidueGraphSetAsnRead(aipr, NULL); AsnIoFlush(aipr); aipr = AsnIoClose(aipr); /* retrieve the bioseq for master and put in ValNode */ sep = (SeqEntryPtr) MakeBioseqs(pbsMaster, stdDictionary); if ( sep == NULL ) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n"); printf("<h3>Unable to get SeqEntry.</h3>\n"); return 0; } ValNodeLink(&(pbsaStruct->sequences), sep); /* PruneBiostruc if Aligned Chain Options has been chosen */ if (Chain) { if (szTemp[4] != ' ') { chain[0] = szTemp[4]; chain[1] = '\0'; pbsTemp = (BiostrucPtr)PruneBiostruc(pbsMaster, chain); pbsMaster = NULL; pbsMaster = pbsTemp; } } /* Make a linked list of Biostrucs of the slave structures*/ while (pbsf) { szTemp = pbsf->name; szName[0] = szTemp[7]; szName[1] = szTemp[8]; szName[2] = szTemp[9]; szName[3] = szTemp[10]; szName[4] = '\0'; if (!pbsSlaveHead) { pbsSlaveHead = FetchBiostrucPDB(szName, complexity, 1); if (!pbsSlaveHead) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3> Unable to load slave structure.</h3>\n"); return 0; } /* Make Bioseq for Slaves */ sep = (SeqEntryPtr) MakeBioseqs(pbsSlaveHead, stdDictionary); if ( sep == NULL ) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n"); printf("<h3>Unable to get SeqEntry.</h3>\n"); return 0; } ValNodeLink(&(pbsaStruct->sequences), sep); /* PruneBiostruc if Aligned Chain Options has been chosen */ if (Chain) { if (szTemp[11] != ' ') { chain[0] = szTemp[11]; chain[1] = '\0'; pbsTemp = (BiostrucPtr)PruneBiostruc(pbsSlaveHead, chain); pbsSlaveHead = NULL; pbsSlaveHead = pbsTemp; } } pbsSlaveTail = pbsSlaveHead; } else { pbsSlave = FetchBiostrucPDB(szName, complexity, 1); if (!pbsSlave) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n"); printf("<h3> Unable to load slave structure.</h3>\n"); return 0; } /* Make Bioseq for Slaves */ sep = (SeqEntryPtr) MakeBioseqs(pbsSlave, stdDictionary); if ( sep == NULL ) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n"); printf("<h3>Unable to get SeqEntry.</h3>\n"); return 0; } ValNodeLink(&(pbsaStruct->sequences), sep); /* PruneBiostruc if Aligned Chain Options has been chosen */ if (Chain) { if (szTemp[11] != ' ') { chain[0] = szTemp[11]; chain[1] = '\0'; pbsTemp = (BiostrucPtr)PruneBiostruc(pbsSlave, chain); pbsSlave = NULL; pbsSlave = pbsTemp; } } pbsSlaveTail->next = pbsSlave; pbsSlaveTail = pbsSlaveTail->next; pbsSlaveTail->next = NULL; } pbsf = pbsf->next; } /* Make a linked list of sequence alignments of master and slaves */ pbsf=pbsfs->features; while (pbsf) { if (!psaAlignHead) { psaAlignHead = fnPBSFtoPSA (pbsf); /* get the sequence alignments */ if (psaAlignHead == NULL || psaAlignHead->data == NULL) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n"); printf("<h3>Unable to create SeqAnnot.</h3>\n"); return 0; } salpHead = (SeqAlignPtr)(psaAlignHead->data); salpTail = salpHead; } else { psaAlignTail = fnPBSFtoPSA (pbsf); salpTail->next = (SeqAlignPtr)(psaAlignTail->data); if (psaAlignTail == NULL || psaAlignTail->data == NULL) { printf("Content-type: text/html\n\n"); printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n"); printf("<h3>Unable to create SeqAnnot.</h3>\n"); return 0; } salpTail = salpTail->next; salpTail->next = NULL; } pbsf = pbsf->next; } pbsaStruct->master = pbsMaster; pbsaStruct->slaves = pbsSlaveHead; pbsaStruct->alignments = pbsaShort; pbsaStruct->seqalign = psaAlignHead; pvnNcbi = ValNodeNew(NULL); pvnNcbi->choice = NcbiMimeAsn1_alignstruc; pvnNcbi->data.ptrvalue = pbsaStruct; pvnNcbi = (NcbiMimeAsn1Ptr) CheckId(pvnNcbi, JobID); /* to check identity, yanli */ OutputFile = stdout; if (iPDB == 0) /* cn3d MIME */ printf ("Content-type: chemical/ncbi-asn1-binary\n\n"); else if (iPDB == 1) { /* "See File" */ printf ("Content-type: text/html\n\n"); printf ("<HTML><body><pre>\n"); } else /* "Save File" */ printf ("Content-type: application/octet-stream\n\n"); if (iPDB != 1) paiFile = AsnIoNew(ASNIO_BIN_OUT, stdout, NULL, NULL, NULL); else paiFile = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL); NcbiMimeAsn1AsnWrite(pvnNcbi, paiFile, NULL); AsnIoFlush(paiFile); AsnIoClose(paiFile); CloseMMDBAPI(); MMDBFini(); VASTFini(); return 0; } /* end of VastToCn3D */
Int2 BLAST_FormatResults(SBlastSeqalignArray* seqalign_arr, Int4 num_queries, SeqLoc* query_slp, SeqLoc* mask_loc_head, BlastFormattingInfo* format_info, Blast_SummaryReturn* sum_returns) { SeqLoc* mask_loc; SeqLoc* next_mask_loc = NULL; SeqLoc* tmp_loc = NULL; Uint1 align_type; Boolean db_is_na; Int4 query_index; SeqLoc* slp; SeqLoc* mask_slp; AsnIo* aip = NULL; MBXml* xmlp = NULL; FILE *outfp = NULL; BlastFormattingOptions* format_options; EAlignView align_view; Boolean ungapped; ASSERT(format_info && format_info->format_options && format_info->search_options && query_slp); format_options = format_info->format_options; align_view = format_options->align_view; ungapped = !format_info->search_options->score_options->gapped_calculation; if (align_view == eAlignViewXml) { const Int4 kXmlFlag = 0; /* Change to BXML_INCLUDE_QUERY if inclusion of query sequence is desired in the XML output header. */ xmlp = format_info->xmlp; if (!xmlp) { xmlp = format_info->xmlp = s_MBXmlInit(format_info->aip, format_info->program_name, format_info->db_name, query_slp, kXmlFlag, sum_returns->search_params); } } else if (align_view == eAlignViewAsnText || align_view == eAlignViewAsnBinary) aip = format_info->aip; else outfp = format_info->outfp; align_type = GetOldAlignType(format_info->search_options->program, &db_is_na); if (format_info->db_name) { /* Enable fetching from the BLAST database. */ ReadDBBioseqFetchEnable ("blast", format_info->db_name, db_is_na, TRUE); /* If database is translated, set the genetic code for tranlation. */ if (Blast_SubjectIsTranslated(format_info->search_options->program)) { ReadDBBioseqSetDbGeneticCode(format_info->search_options-> db_options->genetic_code); } } if(format_info->search_options->score_options->is_ooframe) { ErrPostEx(SEV_WARNING, 0, 0, "Out-of-frame option selected, Expect values are only approximate and calculated not assuming out-of-frame alignments"); } slp = query_slp; mask_loc = mask_loc_head; for (query_index=0; query_index<seqalign_arr->num_queries && slp; query_index++, slp=slp->next) { Bioseq* bsp = NULL; SeqAlignPtr seqalign = seqalign_arr->array[query_index]; /* Find which query the current SeqAlign is for */ SeqId* query_id = TxGetQueryIdFromSeqAlign(seqalign); if (seqalign == NULL) { if (align_view < eAlignViewXml) s_AcknowledgeEmptyResults(slp, format_options, format_info, outfp); /* this query has no results. */ else if (align_view == eAlignViewXml) { /* Retrieve this query's Bioseq */ Iteration* iterp; /* Call to TxGetQueryIdFromSeqAlign returned NULL. */ query_id = SeqLocId(slp); bsp = BioseqLockById(query_id); iterp = s_XMLBuildOneQueryIteration(NULL, sum_returns, FALSE, ungapped, query_index+1+format_info->num_formatted, "No hits found", bsp, NULL); IterationAsnWrite(iterp, xmlp->aip, xmlp->atp); AsnIoFlush(xmlp->aip); IterationFree(iterp); BioseqUnlock(bsp); } else if (align_view == eAlignViewTabularWithComments) { query_id = SeqLocId(slp); bsp = BioseqLockById(query_id); PrintTabularOutputHeader(format_info->db_name, bsp, NULL, format_info->program_name, 0, format_options->believe_query, outfp); BioseqUnlock(bsp); } continue; } format_info->is_seqalign_null = FALSE; /* reset flag, at least one query has seqalign */ /* Find the masking location for this query. Initialize next_mask_loc to the current start of the chain, in case nothing for this query will be found. */ next_mask_loc = mask_loc; for ( ; mask_loc; mask_loc = mask_loc->next) { mask_slp = (SeqLoc*) mask_loc->data.ptrvalue; if (SeqIdComp(query_id, SeqLocId(mask_slp)) == SIC_YES) { break; } } /* Unlink the masking location for this query and save the next one */ if (mask_loc) { for (next_mask_loc = mask_loc; next_mask_loc->next; next_mask_loc = next_mask_loc->next) { mask_slp = (SeqLoc*) next_mask_loc->next->data.ptrvalue; if (SeqIdComp(query_id, SeqLocId(mask_slp)) != SIC_YES) { break; } } tmp_loc = next_mask_loc; next_mask_loc = next_mask_loc->next; tmp_loc->next = NULL; } /* On the next iteration we can start from the next query */ /* Retrieve this query's Bioseq */ bsp = BioseqLockById(query_id); if (align_view < eAlignViewXml) { if (format_info->head_on_every_query == TRUE) BLAST_PrintOutputHeader(format_info); init_buff_ex(70); AcknowledgeBlastQuery(bsp, 70, outfp, format_options->believe_query, format_options->html); free_buff(); if (format_info->head_on_every_query == TRUE) { s_BLAST_PrintDatabaseInfo(format_info); fprintf(format_info->outfp, "%s", "Searching..................................................done\n\n"); } } if (align_view == eAlignViewTabular || align_view == eAlignViewTabularWithComments) { if (align_view == eAlignViewTabularWithComments) PrintTabularOutputHeader(format_info->db_name, bsp, NULL, format_info->program_name, 0, format_options->believe_query, outfp); BlastPrintTabulatedResults(seqalign, bsp, NULL, format_options->number_of_alignments, format_info->program_name, ungapped, format_options->believe_query, 0, 0, outfp, (Boolean)(align_view == eAlignViewTabularWithComments)); } else if(align_view == eAlignViewXml) { Iteration* iterp; ASSERT(xmlp && xmlp->aip); /* The index of this "query iteration" is the query_index in the current formatting round, plus the number of previously formatted queries. */ iterp = s_XMLBuildOneQueryIteration(seqalign, sum_returns, FALSE, ungapped, query_index+1+format_info->num_formatted, NULL, bsp, mask_loc); IterationAsnWrite(iterp, xmlp->aip, xmlp->atp); AsnIoFlush(xmlp->aip); IterationFree(iterp); } else { SeqAnnot* seqannot = SeqAnnotNew(); seqannot->type = 2; AddAlignInfoToSeqAnnot(seqannot, align_type); seqannot->data = seqalign; if (aip) { SeqAnnotAsnWrite((SeqAnnot*) seqannot, aip, NULL); AsnIoReset(aip); } if (outfp) { BlastPruneSapStruct* prune; Int4** matrix = s_LoadMatrix(sum_returns->search_params->matrix); ObjMgrSetHold(); init_buff_ex(85); PrintDefLinesFromSeqAlignEx2(seqalign, 80, outfp, format_options->print_options, FIRST_PASS, NULL, format_options->number_of_descriptions, NULL, NULL); free_buff(); /** @todo FIXME: note that by calling BlastPruneHitsFromSeqAlign * we're making a COPY of the seqalign to print it out! Clearly * this could use a better design */ prune = BlastPruneHitsFromSeqAlign(seqalign, format_options->number_of_alignments, NULL); seqannot->data = prune->sap; if(format_info->search_options->score_options->is_ooframe) { OOFShowBlastAlignment(prune->sap, mask_loc, outfp, format_options->align_options, NULL); } else if (align_view != eAlignViewPairwise) { ShowTextAlignFromAnnot(seqannot, 60, outfp, NULL, NULL, format_options->align_options, matrix, mask_loc, NULL); } else { ShowTextAlignFromAnnot(seqannot, 60, outfp, NULL, NULL, format_options->align_options, matrix, mask_loc, FormatScoreFunc); } s_DeleteMatrix(matrix); seqannot->data = seqalign; prune = BlastPruneSapStructDestruct(prune); ObjMgrClearHold(); } /* Set data to NULL, because we do not free Seq-align here. */ seqannot->data = NULL; seqannot = SeqAnnotFree(seqannot); } BioseqUnlock(bsp); /* Relink the mask locations so chain can be freed in the end. The 'tmp_loc' variable points to the location that was unlinked. */ if (tmp_loc) tmp_loc->next = next_mask_loc; mask_loc = next_mask_loc; ObjMgrFreeCache(0); } /* End loop on seqaligns for different queries */ /* close BlastOutput_iterations openned in s_MBXmlInit; Rt ticket # 15135151 */ if((format_info->is_seqalign_null==TRUE) && (align_view == eAlignViewXml)) { /* extra output only if no hits at all, otherwise "for loop" logic should take care*/ Iteration* iterp; iterp = IterationNew(); iterp->iter_num = 1; iterp->stat = s_XMLBuildStatistics(sum_returns, ungapped); ASSERT(xmlp && xmlp->aip); IterationAsnWrite(iterp, xmlp->aip, xmlp->atp); AsnIoFlush(xmlp->aip); IterationFree(iterp); } if (format_info->db_name) { /* Free the database translation tables, if applicable. */ TransTableFreeAll(); ReadDBBioseqFetchDisable(); } /* Update the count of the formatted queries. */ format_info->num_formatted += num_queries; return 0; }
/** Initializes the XML output structure and prints the XML output header. * @param aip ASN.1 output stream [in] * @param program BLAST program name [in] * @param database BLAST database name [in] * @param query_loc Query Seq-loc [in] * @param flags Flag for query sequence inclusion [in] * @param search_params BLAST search parameters [in] * @return Initialized structure for printing XML output. */ static MBXml* s_MBXmlInit(AsnIo* aip, char* program, char* database, SeqLoc* query_loc, Int4 flags, Blast_SearchParams* search_params) { MBXml* xmlp; AsnModule* amp; DataVal av; AsnType* atp; Boolean retval = FALSE; AsnType* BLASTOUTPUT; AsnType* BLASTOUTPUT_program; AsnType* BLASTOUTPUT_version; AsnType* BLASTOUTPUT_reference; AsnType* BLASTOUTPUT_db; AsnType* BLASTOUTPUT_query_ID; AsnType* BLASTOUTPUT_query_def; AsnType* BLASTOUTPUT_query_len; AsnType* BLASTOUTPUT_query_seq; AsnType* BLASTOUTPUT_param; AsnType* BLASTOUTPUT_iterations; AsnType* BLASTOUTPUT_iterations_E; AsnType* BLASTOUTPUT_mbstat; if (strcmp(program, "rpsblast") == 0) program = "blastp"; else if (strcmp(program, "rpstblastn") == 0) program = "blastx"; AsnSetXMLmodulePrefix("http://www.ncbi.nlm.nih.gov/dtd/"); xmlp = (MBXml*) MemNew(sizeof(MBXml)); xmlp->aip = aip; if (! bxmlobjAsnLoad()) { return NULL; } amp = AsnAllModPtr(); MACRO_atp_find(BLASTOUTPUT,BlastOutput); MACRO_atp_find(BLASTOUTPUT_program,BlastOutput.program); MACRO_atp_find(BLASTOUTPUT_version,BlastOutput.version); MACRO_atp_find(BLASTOUTPUT_reference,BlastOutput.reference); MACRO_atp_find(BLASTOUTPUT_db,BlastOutput.db); MACRO_atp_find(BLASTOUTPUT_query_ID,BlastOutput.query-ID); MACRO_atp_find(BLASTOUTPUT_query_def,BlastOutput.query-def); MACRO_atp_find(BLASTOUTPUT_query_len,BlastOutput.query-len); MACRO_atp_find(BLASTOUTPUT_query_seq,BlastOutput.query-seq); MACRO_atp_find(BLASTOUTPUT_param,BlastOutput.param); MACRO_atp_find(BLASTOUTPUT_iterations,BlastOutput.iterations); MACRO_atp_find(BLASTOUTPUT_iterations_E,BlastOutput.iterations.E); MACRO_atp_find(BLASTOUTPUT_mbstat,BlastOutput.mbstat); /* Start of iterations structure */ xmlp->atp = BLASTOUTPUT_iterations_E; /* Head of all BlastOutput structure */ xmlp->BlastOutput = BLASTOUTPUT; /* Head of iterations strucure */ xmlp->BlastOutput_iterations = BLASTOUTPUT_iterations; /* Head of the final statistics for Mega BLAST */ xmlp->BlastOutput_mbstat = BLASTOUTPUT_mbstat; xmlp->boutp = s_CreateBlastOutputHead(program, database, query_loc, flags, search_params); atp = AsnLinkType(NULL, BLASTOUTPUT); /* link local tree */ if (atp == NULL) { return NULL; } if (! AsnOpenStruct(xmlp->aip, atp, (Pointer) xmlp->boutp)) { return NULL; } if (xmlp->boutp->program != NULL) { av.ptrvalue = xmlp->boutp -> program; retval = AsnWrite(xmlp->aip, BLASTOUTPUT_program, &av); } if (xmlp->boutp->version != NULL) { av.ptrvalue = xmlp->boutp->version; retval = AsnWrite(xmlp->aip, BLASTOUTPUT_version, &av); } if (xmlp->boutp->reference != NULL) { av.ptrvalue = xmlp->boutp->reference; retval = AsnWrite(xmlp->aip, BLASTOUTPUT_reference, &av); } if (xmlp->boutp -> db != NULL) { av.ptrvalue = xmlp->boutp->db; retval = AsnWrite(xmlp->aip, BLASTOUTPUT_db, &av); } if (xmlp->boutp -> query_ID != NULL) { av.ptrvalue = xmlp->boutp->query_ID; retval = AsnWrite(xmlp->aip, BLASTOUTPUT_query_ID, &av); } if (xmlp->boutp->query_def != NULL) { av.ptrvalue = xmlp->boutp->query_def; retval = AsnWrite(xmlp->aip, BLASTOUTPUT_query_def, &av); } av.intvalue = xmlp->boutp->query_len; retval = AsnWrite(xmlp->aip, BLASTOUTPUT_query_len, &av); if (xmlp->boutp->query_seq != NULL) { av.ptrvalue = xmlp->boutp->query_seq; retval = AsnWrite(xmlp->aip, BLASTOUTPUT_query_seq, &av); } if (xmlp->boutp->param != NULL) { if (!ParametersAsnWrite(xmlp->boutp->param, xmlp->aip, BLASTOUTPUT_param)) { return NULL; } } if(!AsnOpenStruct(xmlp->aip, BLASTOUTPUT_iterations, NULL)) return NULL; AsnIoFlush(xmlp->aip); return xmlp; }
Int2 LIBCALLBACK VSMDescriptorAsnSave (Pointer data) { OMProcControlPtr ompcp; Char filename[255]; SelStructPtr ssp, sel; SeqDescrPtr sdp; BioseqPtr bsp; SeqEntryPtr sep; SeqMgrDescContext dcontext; #ifdef WIN_MAC FILE * fp; #endif ValNodePtr vnp; SaveSetSdpData sd; ValNodePtr obj_list = NULL; ompcp = (OMProcControlPtr)data; if (ompcp == NULL) return OM_MSG_RET_ERROR; sd.already_have_molinfo = FALSE; ssp = ObjMgrGetSelected(); if (ssp == NULL) { Message (MSG_ERROR, "You must select a sequence or set from which descriptors should be saved"); return OM_MSG_RET_DONE; } else { for (sel = ssp; sel != NULL; sel = sel->next) { GatherItem (sel->entityID, sel->itemID, sel->itemtype, (Pointer) &obj_list, AddToSaveList); } } /* get file name to use */ filename[0] = '\0'; if (GetOutputFileName(filename, (size_t)254, NULL)) { WatchCursor(); #ifdef WIN_MAC fp = FileOpen (filename, "r"); if (fp != NULL) { FileClose (fp); } else { FileCreate (filename, "TEXT", "ttxt"); } #endif sd.aip = AsnIoOpen(filename, "w"); for (vnp = obj_list; vnp != NULL; vnp = vnp->next) { switch (vnp->choice) { case OBJ_SEQDESC: sdp = (SeqDescrPtr) vnp->data.ptrvalue; SeqDescAsnWrite (sdp, sd.aip, NULL); AsnPrintNewLine (sd.aip); AsnIoFlush (sd.aip); break; case OBJ_BIOSEQ: bsp = (BioseqPtr) vnp->data.ptrvalue; for (sdp = SeqMgrGetNextDescriptor (bsp, NULL, 0, &dcontext); sdp != NULL; sdp = SeqMgrGetNextDescriptor (bsp, sdp, 0, &dcontext)) { if (sdp->choice != Seq_descr_source && sdp->choice != Seq_descr_pub && sdp->choice != Seq_descr_molinfo && sdp->choice != Seq_descr_comment) continue; SeqDescAsnWrite (sdp, sd.aip, NULL); AsnPrintNewLine (sd.aip); AsnIoFlush (sd.aip); } break; case OBJ_BIOSEQSET: sep = SeqMgrGetSeqEntryForData (vnp->data.ptrvalue); VisitDescriptorsInSep (sep, &sd, SaveSetDescriptors); break; } } AsnIoClose(sd.aip); ArrowCursor(); } return OM_MSG_RET_DONE; }
static Int2 Main_old (void) { AsnIoPtr aip, xml_aip = NULL; BioseqPtr query_bsp, PNTR query_bsp_array; BioSourcePtr source; BLAST_MatrixPtr matrix; BLAST_OptionsBlkPtr options; BLAST_KarlinBlkPtr ka_params=NULL, ka_params_gap=NULL; BlastPruneSapStructPtr prune; Boolean db_is_na, query_is_na, show_gi, believe_query=FALSE; Boolean html=FALSE; CharPtr params_buffer=NULL; Int4 number_of_descriptions, number_of_alignments; SeqAlignPtr seqalign, PNTR seqalign_array; SeqAnnotPtr seqannot; SeqEntryPtr PNTR sepp; TxDfDbInfoPtr dbinfo=NULL, dbinfo_head; Uint1 align_type, align_view, out_type; Uint4 align_options, print_options; ValNodePtr mask_loc, mask_loc_start, next_mask_loc; ValNodePtr vnp, other_returns, error_returns; CharPtr blast_program, blast_database, blast_inputfile, blast_outputfile; FILE *infp, *outfp, *mqfp=NULL; Int4 index, num_bsps, total_length, total_processed = 0; Int2 ctr = 1; Char prefix[2]; SeqLocPtr last_mask, mask_slp; Boolean done, hits_found; Boolean lcase_masking; MBXmlPtr mbxp = NULL; Boolean traditional_formatting; blast_program = "blastn"; blast_database = myargs [ARG_DB].strvalue; blast_inputfile = myargs [ARG_QUERY].strvalue; blast_outputfile = myargs [ARG_OUT].strvalue; if (myargs[ARG_HTML].intvalue) html = TRUE; if ((infp = FileOpen(blast_inputfile, "r")) == NULL) { ErrPostEx(SEV_FATAL, 1, 0, "mgblast: Unable to open input file %s\n", blast_inputfile); return (1); } align_view = (Int1) myargs[ARG_FORMAT].intvalue; /* Geo mod: -- replaced myargs[ARG_OUTTYPE].intvalue with out_type from now on */ out_type=(Int1) myargs[ARG_OUTTYPE].intvalue; if (out_type==MGBLAST_FLTHITS || out_type==MGBLAST_HITGAPS) { align_view = 12 + (out_type-MGBLAST_FLTHITS ); out_type=MBLAST_ALIGNMENTS; //Attention: 12 MUST be the -m mgblast tab option for MGBLAST_FLTHITS format // and MGBLAST_HITGAPS = MGBLAST_FLTHITS+1 if (align_view>12) { // this is MGBLAST_HITGAPS output gap_Info=TRUE; if (dbgaps_buf==NULL) dbgaps_buf=(CharPtr) Malloc(dbgaps_bufsize + 1); if (qgaps_buf==NULL) qgaps_buf=(CharPtr) Malloc(qgaps_bufsize + 1); } } outfp = NULL; traditional_formatting = (out_type == MBLAST_ALIGNMENTS || out_type == MBLAST_DELAYED_TRACEBACK); if ((!traditional_formatting || (align_view != 7 && align_view != 10 && align_view != 11)) && blast_outputfile != NULL) { if ((outfp = FileOpen(blast_outputfile, "w")) == NULL) { ErrPostEx(SEV_FATAL, 1, 0, "blast: Unable to open output file %s\n", blast_outputfile); return (1); } } //align_type = BlastGetTypes(blast_program, &query_is_na, &db_is_na); align_type = BlastGetTypes(blast_program, &query_is_na, &db_is_na); /* if (!traditional_formatting) believe_query = TRUE; else believe_query = (Boolean) myargs[ARG_BELIEVEQUERY].intvalue; */ //Geo mod: believe_query=FALSE; //If ASN.1 output is requested and believe_query is not set to TRUE, // exit with an error. if (!believe_query && (myargs[ARG_ASNOUT].strvalue || align_view == 10 || align_view == 11)) { ErrPostEx(SEV_FATAL, 1, 0, "-J option must be TRUE to produce ASN.1 output; before " "changing -J to TRUE please also ensure that all query " "sequence identifiers are unique"); return -1; } options = BLASTOptionNewEx(blast_program, TRUE, TRUE); if (options == NULL) return 3; options->do_sum_stats = FALSE; options->is_neighboring = FALSE; options->expect_value = (Nlm_FloatHi) myargs [ARG_EVALUE].floatvalue; number_of_descriptions = myargs[ARG_DESCRIPTIONS].intvalue; number_of_alignments = myargs[ARG_ALIGNMENTS].intvalue; options->hitlist_size = MAX(number_of_descriptions, number_of_alignments); if (myargs[ARG_XDROP].intvalue != 0) options->gap_x_dropoff = myargs[ARG_XDROP].intvalue; if (myargs[ARG_XDROP_UNGAPPED].intvalue != 0) options->dropoff_2nd_pass = myargs[ARG_XDROP_UNGAPPED].intvalue; if (myargs[ARG_XDROP_FINAL].intvalue != 0) options->gap_x_dropoff_final = myargs[ARG_XDROP_FINAL].intvalue; if (StringICmp(myargs[ARG_FILTER].strvalue, "T") == 0) options->filter_string = StringSave("D"); else options->filter_string = StringSave(myargs[ARG_FILTER].strvalue); show_gi = (Boolean) myargs[ARG_SHOWGIS].intvalue; options->penalty = myargs[ARG_MISMATCH].intvalue; options->reward = myargs[ARG_MATCH].intvalue; if (myargs[ARG_GAPOPEN].intvalue >= 0) options->gap_open = myargs[ARG_GAPOPEN].intvalue; if (myargs[ARG_GAPEXT].intvalue >= 0) options->gap_extend = myargs[ARG_GAPEXT].intvalue; if (options->gap_open == 0 && options->reward % 2 == 0 && options->gap_extend == options->reward / 2 - options->penalty) /* This is the default value */ options->gap_extend = 0; options->genetic_code = 1; options->db_genetic_code = 1; /* Default; it's not needed here anyway */ options->number_of_cpus = myargs[ARG_THREADS].intvalue; if (myargs[ARG_WORDSIZE].intvalue != 0) options->wordsize = myargs[ARG_WORDSIZE].intvalue; if (myargs[ARG_MINSCORE].intvalue == 0) options->cutoff_s2 = options->wordsize*options->reward; else options->cutoff_s2 = myargs[ARG_MINSCORE].intvalue; options->db_length = (Int8) myargs[ARG_DBSIZE].floatvalue; options->searchsp_eff = (Nlm_FloatHi) myargs[ARG_SEARCHSP].floatvalue; options->perform_culling = FALSE; /* Kludge */ options->block_width = myargs[ARG_MAXPOS].intvalue; options->strand_option = myargs[ARG_STRAND].intvalue; options->window_size = myargs[ARG_WINDOW].intvalue; #ifdef DO_NOT_SUPPRESS_BLAST_OP options->mb_template_length = myargs[ARG_TEMPL_LEN].intvalue; if (myargs[ARG_TEMPL_LEN].intvalue != 0) options->mb_one_base_step = (Boolean) myargs[ARG_EVERYBASE].intvalue; options->mb_disc_type = myargs[ARG_TEMPL_TYPE].intvalue; #endif lcase_masking = (Boolean) myargs[ARG_LCASE].intvalue; /* Allow dynamic programming gapped extension only with affine gap scores */ if (options->gap_open != 0 || options->gap_extend != 0) options->mb_use_dyn_prog = (Boolean) myargs[ARG_DYNAMIC].intvalue; print_options = 0; align_options = 0; align_options += TXALIGN_COMPRESS; align_options += TXALIGN_END_NUM; if (show_gi) { align_options += TXALIGN_SHOW_GI; print_options += TXALIGN_SHOW_GI; } if (align_view) { align_options += TXALIGN_MASTER; if (align_view == 1 || align_view == 3) align_options += TXALIGN_MISMATCH; if (align_view == 3 || align_view == 4 || align_view == 6) align_options += TXALIGN_FLAT_INS; if (align_view == 5 || align_view == 6) align_options += TXALIGN_BLUNT_END; } else { align_options += TXALIGN_MATRIX_VAL; align_options += TXALIGN_SHOW_QS; } if (html) { align_options += TXALIGN_HTML; print_options += TXALIGN_HTML; } if (myargs[ARG_GILIST].strvalue) options->gifile = StringSave(myargs[ARG_GILIST].strvalue); if (out_type == MBLAST_ENDPOINTS) options->no_traceback = 1; else if (out_type == MBLAST_DELAYED_TRACEBACK) options->no_traceback = 2; else options->no_traceback = 0; options->megablast_full_deflines = (Boolean) myargs[ARG_FULLID].intvalue; options->perc_identity = (FloatLo) myargs[ARG_PERC_IDENT].floatvalue; options->hsp_num_max = myargs[ARG_MAXHSP].intvalue; if (!believe_query) options->megablast_full_deflines = TRUE; /*if (options->megablast_full_deflines) believe_query = FALSE;*/ query_bsp_array = (BioseqPtr PNTR) MemNew((MAX_NUM_QUERIES+1)*sizeof(BioseqPtr)); sepp = (SeqEntryPtr PNTR) MemNew(MAX_NUM_QUERIES*sizeof(SeqEntryPtr)); StrCpy(prefix, ""); global_fp = outfp; options->output = outfp; if (traditional_formatting) { if (align_view < 7) { if (html) { fprintf(outfp, "<HTML>\n<TITLE>MEGABLAST Search Results</TITLE>\n"); fprintf(outfp, "<BODY BGCOLOR=\"#FFFFFF\" LINK=\"#0000FF\" " "VLINK=\"#660099\" ALINK=\"#660099\">\n"); fprintf(outfp, "<PRE>\n"); } init_buff_ex(90); BlastPrintVersionInfo("mgblast", html, outfp); fprintf(outfp, "\n"); MegaBlastPrintReference(html, 90, outfp); fprintf(outfp, "\n"); if(!PrintDbInformation(blast_database, !db_is_na, 70, outfp, html)) return 1; free_buff(); #ifdef OS_UNIX fprintf(global_fp, "%s", "Searching"); #endif } } aip = NULL; if (myargs[ARG_ASNOUT].strvalue != NULL) { if ((aip = AsnIoOpen (myargs[ARG_ASNOUT].strvalue,"w")) == NULL) { ErrPostEx(SEV_FATAL, 1, 0, "blast: Unable to open output file %s\n", myargs[ARG_ASNOUT].strvalue); return 1; } } else if (align_view == 10 || align_view == 11) { const char* mode = (align_view == 10) ? "w" : "wb"; if ((aip = AsnIoOpen (blast_outputfile, (char*) mode)) == NULL) { ErrPostEx(SEV_FATAL, 1, 0, "blast: Unable to open output file %s\n", blast_outputfile); return 1; } } if (align_view == 7) { xml_aip = AsnIoOpen(blast_outputfile, "wx"); } if (myargs[ARG_QUERYLOC].strvalue) { Int4 start, end; Megablast_GetLoc(myargs[ARG_QUERYLOC].strvalue, &start, &end); options->required_start = start - 1; options->required_end = end -1; } done = FALSE; while (!done) { num_bsps = 0; total_length = 0; done = TRUE; SeqMgrHoldIndexing(TRUE); mask_slp = last_mask = NULL; while ((sepp[num_bsps]=FastaToSeqEntryForDb(infp, query_is_na, NULL, believe_query, prefix, &ctr, &mask_slp)) != NULL) { if (!lcase_masking) /* Lower case ignored */ mask_slp = SeqLocFree(mask_slp); if (mask_slp) { if (!last_mask) options->query_lcase_mask = last_mask = mask_slp; else { last_mask->next = mask_slp; last_mask = last_mask->next; } mask_slp = NULL; } query_bsp = NULL; SeqEntryExplore(sepp[num_bsps], &query_bsp, FindNuc); //debug: /* char query_buffer[255]; SeqIdWrite(query_bsp->id, query_buffer, PRINTID_FASTA_LONG, BUFFER_LENGTH); fprintf(stderr, "===> query_buf=%s\n", query_buffer); */ if (query_bsp == NULL) { ErrPostEx(SEV_FATAL, 1, 0, "Unable to obtain bioseq\n"); return 2; } source = BioSourceNew(); source->org = OrgRefNew(); source->org->orgname = OrgNameNew(); source->org->orgname->gcode = options->genetic_code; ValNodeAddPointer(&(query_bsp->descr), Seq_descr_source, source); query_bsp_array[num_bsps++] = query_bsp; total_length += query_bsp->length; if (total_length > myargs[ARG_MAXQUERY].intvalue || num_bsps >= MAX_NUM_QUERIES) { done = FALSE; break; } } if (num_bsps == 0) break; SeqMgrHoldIndexing(FALSE); other_returns = NULL; error_returns = NULL; if (out_type==MBLAST_ENDPOINTS) seqalign_array = BioseqMegaBlastEngine(query_bsp_array, blast_program, blast_database, options, &other_returns, &error_returns, dummy_callback, NULL, NULL, 0, MegaBlastPrintEndpoints); else if (out_type==MBLAST_SEGMENTS) seqalign_array = BioseqMegaBlastEngine(query_bsp_array, blast_program, blast_database, options, &other_returns, &error_returns, dummy_callback, NULL, NULL, 0, MegaBlastPrintSegments); else if (out_type==MBLAST_ALIGN_INFO) { /* -- Geo mod: do not print header PrintTabularOutputHeader(blast_database, (num_bsps==1) ? query_bsp_array[0] : NULL, NULL, "megablast", 0, believe_query, global_fp);*/ seqalign_array = BioseqMegaBlastEngine(query_bsp_array, blast_program, blast_database, options, &other_returns, &error_returns, dummy_callback, NULL, NULL, 0, MegaBlastPrintAlignInfo); } else if (out_type==MBLAST_ALIGNMENTS) { seqalign_array = BioseqMegaBlastEngine(query_bsp_array, blast_program, blast_database, options, &other_returns, &error_returns, align_view < 7 ? tick_callback : NULL, NULL, NULL, 0, NULL); } #ifdef OS_UNIX fflush(global_fp); #endif if (error_returns) { BlastErrorPrint(error_returns); for (vnp = error_returns; vnp; vnp = vnp->next) { BlastDestroyErrorMessage((BlastErrorMsgPtr)vnp->data.ptrvalue); } ValNodeFree(error_returns); } if (traditional_formatting) { dbinfo = NULL; ka_params = NULL; ka_params_gap = NULL; params_buffer = NULL; mask_loc = NULL; matrix = NULL; for (vnp=other_returns; vnp; vnp = vnp->next) { switch (vnp->choice) { case TXDBINFO: dbinfo = vnp->data.ptrvalue; break; case TXKABLK_NOGAP: ka_params = vnp->data.ptrvalue; break; case TXKABLK_GAP: ka_params_gap = vnp->data.ptrvalue; break; case TXPARAMETERS: params_buffer = vnp->data.ptrvalue; break; case TXMATRIX: matrix = vnp->data.ptrvalue; break; case SEQLOC_MASKING_NOTSET: case SEQLOC_MASKING_PLUS1: case SEQLOC_MASKING_PLUS2: case SEQLOC_MASKING_PLUS3: case SEQLOC_MASKING_MINUS1: case SEQLOC_MASKING_MINUS2: case SEQLOC_MASKING_MINUS3: ValNodeAddPointer(&mask_loc, vnp->choice, vnp->data.ptrvalue); break; default: break; } } #ifdef OS_UNIX if(align_view < 7) { fprintf(global_fp, "%s\n", " done"); } #endif if (myargs[ARG_MASKEDQUERY].strvalue) { if ((mqfp = FileOpen(myargs[ARG_MASKEDQUERY].strvalue, "w")) == NULL) ErrPostEx(SEV_WARNING, 1, 0, "Unable to open file %s for masked query\n", myargs[ARG_MASKEDQUERY].strvalue); } hits_found = FALSE; mask_loc_start = next_mask_loc = mask_loc; mask_loc = NULL; if (align_view == 7) { mbxp = PSIXmlInit(xml_aip, "megablast", blast_database, options, query_bsp_array[0], 0); } if (seqalign_array) { //results returned back for processing ReadDBBioseqFetchEnable ("megablast", blast_database, db_is_na, TRUE); for (index=0; index<num_bsps; index++) { seqalign = seqalign_array[index]; if (next_mask_loc && SeqIdComp(SeqLocId((SeqLocPtr)next_mask_loc->data.ptrvalue), query_bsp_array[index]->id) == SIC_YES) { mask_loc = (SeqLocPtr) MemDup(next_mask_loc, sizeof(SeqLoc)); next_mask_loc = next_mask_loc->next; mask_loc->next = NULL; } if (mqfp) { /* convert mask locations from all sources into a single seqloc */ mask_slp = NULL; if (mask_loc) mask_slp = blastMergeFilterLocs(mask_slp, (SeqLocPtr)mask_loc->data.ptrvalue, FALSE, 0, 0); PrintMaskedSequence(query_bsp_array[index], mask_slp, mqfp, 50, lcase_masking); SeqLocSetFree(mask_slp); } if (seqalign==NULL) { mask_loc = MemFree(mask_loc); continue; } hits_found = TRUE; if (align_view < 7) { init_buff_ex(70); AcknowledgeBlastQuery(query_bsp_array[index], 70, outfp, believe_query, html); free_buff(); } if (align_view == 8 || align_view == 9) { if (align_view == 9) PrintTabularOutputHeader(blast_database, query_bsp_array[index], NULL, blast_program, 0, believe_query, global_fp); /* debug: char qbuf[512]; strcpy(qbuf, BioseqGetTitle(query_bsp_array[index])); fprintf(stderr, "---> Here: query title=%s\n", qbuf); */ BlastPrintTabulatedResults(seqalign, query_bsp_array[index], NULL, number_of_alignments, blast_program, !options->gapped_calculation, believe_query, 0, 0, global_fp, (align_view == 9)); ObjMgrFreeCache(0); SeqAlignSetFree(seqalign); mask_loc = MemFree(mask_loc); continue; } //Geo mod: else if (align_view>=12) { MGBlastPrintTab(seqalign, query_bsp_array[index], number_of_alignments, !options->gapped_calculation, global_fp); ObjMgrFreeCache(0); SeqAlignSetFree(seqalign); mask_loc = MemFree(mask_loc); continue; } else if(align_view == 7) { IterationPtr iterp; iterp = BXMLBuildOneQueryIteration(seqalign, NULL, FALSE, !options->gapped_calculation, index, NULL, query_bsp_array[index], mask_loc); IterationAsnWrite(iterp, mbxp->aip, mbxp->atp); AsnIoFlush(mbxp->aip); IterationFree(iterp); SeqAlignSetFree(seqalign); mask_loc = MemFree(mask_loc); continue; } seqannot = SeqAnnotNew(); seqannot->type = 2; AddAlignInfoToSeqAnnot(seqannot, align_type); seqannot->data = seqalign; if (aip) { SeqAnnotAsnWrite((SeqAnnotPtr) seqannot, aip, NULL); AsnIoReset(aip); } if (outfp) { /* Uncacheing causes problems with ordinal nos. vs. gi's. */ prune = BlastPruneHitsFromSeqAlign(seqalign, number_of_descriptions, NULL); ObjMgrSetHold(); init_buff_ex(85); PrintDefLinesFromSeqAlign(prune->sap, 80, outfp, print_options, FIRST_PASS, NULL); free_buff(); prune = BlastPruneHitsFromSeqAlign(seqalign, number_of_alignments, prune); seqannot->data = prune->sap; if (align_view != 0) ShowTextAlignFromAnnot(seqannot, 60, outfp, NULL, NULL, align_options, NULL, mask_loc, NULL); else ShowTextAlignFromAnnot(seqannot, 60, outfp, NULL, NULL, align_options, NULL, mask_loc, FormatScoreFunc); seqannot->data = seqalign; prune = BlastPruneSapStructDestruct(prune); ObjMgrClearHold(); ObjMgrFreeCache(0); } seqannot = SeqAnnotFree(seqannot); mask_loc = MemFree(mask_loc); } /* End loop on seqaligns for different queries */ ReadDBBioseqFetchDisable(); } if (mbxp != NULL) { MBXmlClose(mbxp, other_returns, !options->gapped_calculation); } if (mqfp) FileClose(mqfp); if (!hits_found && align_view < 7) fprintf(outfp, "\n\n ***** No hits found ******\n\n"); matrix = BLAST_MatrixDestruct(matrix); if(html) fprintf(outfp, "<PRE>\n"); init_buff_ex(85); dbinfo_head = dbinfo; if(align_view < 7) { while (dbinfo) { PrintDbReport(dbinfo, 70, outfp); dbinfo = dbinfo->next; } } dbinfo_head = TxDfDbInfoDestruct(dbinfo_head); if (ka_params) { if(align_view < 7) PrintKAParameters(ka_params->Lambda, ka_params->K, ka_params->H, 70, outfp, FALSE); MemFree(ka_params); } if (ka_params_gap) { if(align_view < 7) PrintKAParameters(ka_params_gap->Lambda, ka_params_gap->K, ka_params_gap->H, 70, outfp, TRUE); MemFree(ka_params_gap); } if(align_view < 7) PrintTildeSepLines(params_buffer, 70, outfp); MemFree(params_buffer); free_buff(); mask_loc = mask_loc_start; while (mask_loc) { SeqLocSetFree(mask_loc->data.ptrvalue); mask_loc = mask_loc->next; } ValNodeFree(mask_loc_start); } else { //not traditional formatting /* Just destruct all other_returns parts */ for (vnp=other_returns; vnp; vnp = vnp->next) { switch (vnp->choice) { case TXDBINFO: TxDfDbInfoDestruct(vnp->data.ptrvalue); break; case TXKABLK_NOGAP: case TXKABLK_GAP: case TXPARAMETERS: MemFree(vnp->data.ptrvalue); break; case TXMATRIX: BLAST_MatrixDestruct(vnp->data.ptrvalue); break; case SEQLOC_MASKING_NOTSET: case SEQLOC_MASKING_PLUS1: case SEQLOC_MASKING_PLUS2: case SEQLOC_MASKING_PLUS3: case SEQLOC_MASKING_MINUS1: case SEQLOC_MASKING_MINUS2: case SEQLOC_MASKING_MINUS3: mask_loc = vnp->data.ptrvalue; SeqLocSetFree(mask_loc); default: break; } } } other_returns = ValNodeFree(other_returns); MemFree(seqalign_array); options->query_lcase_mask = SeqLocSetFree(options->query_lcase_mask); /* Freeing SeqEntries can be very expensive, do this only if this is not the last iteration of search */ if (!done) { for (index=0; index<num_bsps; index++) { sepp[index] = SeqEntryFree(sepp[index]); query_bsp_array[index] = NULL; } } total_processed += num_bsps; } /* End of loop on complete searches */ aip = AsnIoClose(aip); /*if (align_view == 7) xml_aip = AsnIoClose(xml_aip);*/ if (align_view < 7 && html) fprintf(outfp, "</PRE>\n</BODY>\n</HTML>\n"); if (align_view < 7 && myargs[ARG_LOGINFO].intvalue) fprintf(outfp, "Mega BLAST run finished, processed %d queries\n", total_processed); MemFree(query_bsp_array); MemFree(sepp); MemFree(qgaps_buf); MemFree(dbgaps_buf); options = BLASTOptionDelete(options); FileClose(infp); FileClose(outfp); return 0; }
void AsnMemoryWrite::flush(void) const { AsnIoFlush(m_Out); }