void COMSSAMerge::Init() { auto_ptr<CArgDescriptions> argDesc(new CArgDescriptions); argDesc->AddDefaultKey("i", "infiles", "file containing list of input files on separate lines", CArgDescriptions::eString, ""); argDesc->AddFlag("sw", "output search results without spectra"); argDesc->AddFlag("it", "input as text asn.1 formatted search results"); argDesc->AddFlag("ib", "input as binary asn.1 formatted search results"); argDesc->AddFlag("ix", "input as xml formatted search results"); argDesc->AddFlag("ibz2", "input as xml formatted search results compressed by bzip2"); argDesc->AddPositional("o", "output file name", CArgDescriptions::eString); argDesc->AddFlag("ot", "output as text asn.1 formatted search results"); argDesc->AddFlag("ob", "output as binary asn.1 formatted search results"); argDesc->AddFlag("ox", "output as xml formatted search results"); argDesc->AddFlag("obz2", "output as xml formatted search results compressed by bzip2"); argDesc->AddExtra(0,10000, "input file names", CArgDescriptions::eString); SetupArgDescriptions(argDesc.release()); // allow info posts to be seen SetDiagPostLevel(eDiag_Info); }
void CTestApplication::Init(void) { // Set err.-posting and tracing to maximum SetDiagTrace(eDT_Enable); SetDiagPostFlag(eDPF_All); SetDiagPostLevel(eDiag_Info); }
void CBDB_TestThreads::Init(void) { SetDiagTrace(eDT_Enable); SetDiagPostLevel(eDiag_Warning); SetDiagPostFlag(eDPF_File); SetDiagPostFlag(eDPF_Line); SetDiagPostFlag(eDPF_Trace); auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); arg_desc->SetUsageContext("test_bdb_threads", "test BDB library with threads"); arg_desc->AddOptionalKey("recs", "recs", "Number of records to load per thread", CArgDescriptions::eInteger); arg_desc->AddOptionalKey("threads", "threads", "Number of concurrent threads", CArgDescriptions::eInteger); SetupArgDescriptions(arg_desc.release()); }
int CServerTestApp::Run(void) { SetDiagPostLevel(eDiag_Info); SetDiagPostAllFlags(eDPF_Severity | eDPF_OmitInfoSev | eDPF_ErrorID); #if defined(NCBI_OS_MSWIN) || defined(NCBI_OS_CYGWIN) CRequestRateControl rate_control(6); #else CRequestRateControl rate_control(CRequestRateControl::kNoLimit); #endif CFastMutex rate_mutex; const CArgs& args = GetArgs(); unsigned short port = 4096; { CListeningSocket listener; while (++port & 0xFFFF) { if (listener.Listen(port, 5, fSOCK_BindAny | fSOCK_LogOff) == eIO_Success) break; } if (port == 0) { ERR_POST("CServer test: unable to find a free port to listen on"); return 2; } } SServer_Parameters params; params.init_threads = args["srvthreads"].AsInteger(); params.max_threads = args["maxsrvthreads"].AsInteger(); params.accept_timeout = &kAcceptTimeout; int max_number_of_clients = args["requests"].AsInteger(); CTestServer server(max_number_of_clients, args["maxdelay"].AsInteger()); server.SetParameters(params); server.AddListener(new CTestConnectionFactory(&server), port); server.StartListening(); CStdPoolOfThreads pool(args["maxclthreads"].AsInteger(), max_number_of_clients); pool.Spawn(args["clthreads"].AsInteger()); for (int i = max_number_of_clients; i > 0; i--) { pool.AcceptRequest(CRef<ncbi::CStdRequest> (new CConnectionRequest(port, rate_control, rate_mutex))); } server.Run(); pool.KillAllThreads(true); return 0; }
int main(int argc, const char* argv[]) { SetDiagStream(&NcbiCerr); // send all diagnostic messages to cerr SetDiagPostLevel(eDiag_Info); // show all messages CAVApp app; return app.AppMain(argc, argv, NULL, eDS_Default, NULL); // don't use config file }
void CTestTransmission::Init(void) { SetDiagPostLevel(eDiag_Warning); unique_ptr<CArgDescriptions> d(new CArgDescriptions); d->SetUsageContext("test_transmissionrw", "test transmission reader/writer"); SetupArgDescriptions(d.release()); }
CRef<CObjectManager> sx_GetOM(void) { SetDiagPostLevel(eDiag_Info); CRef<CObjectManager> om = CObjectManager::GetInstance(); CObjectManager::TRegisteredNames names; om->GetRegisteredNames(names); ITERATE ( CObjectManager::TRegisteredNames, it, names ) { om->RevokeDataLoader(*it); }
void CDBAPI_CacheTest::Init(void) { SetDiagPostLevel(eDiag_Warning); SetDiagPostFlag(eDPF_File); SetDiagPostFlag(eDPF_Line); auto_ptr<CArgDescriptions> d(new CArgDescriptions); d->SetUsageContext("test_bdb", "test BDB library"); SetupArgDescriptions(d.release()); }
void CTestTable::Init(void) { SetDiagPostLevel(eDiag_Warning); auto_ptr<CArgDescriptions> d(new CArgDescriptions); d->SetUsageContext("test_table", "test NCBI table"); SetupArgDescriptions(d.release()); }
void CBDB_PhoneBookDemo1::Init(void) { SetDiagPostLevel(eDiag_Warning); SetDiagPostFlag(eDPF_File); SetDiagPostFlag(eDPF_Line); auto_ptr<CArgDescriptions> d(new CArgDescriptions); d->SetUsageContext("bdb demo1", "Demo1 application for BDB library"); SetupArgDescriptions(d.release()); }
void CTestIdMux::Init(void) { SetDiagPostLevel(eDiag_Warning); unique_ptr<CArgDescriptions> d(new CArgDescriptions); d->SetUsageContext("test_id_mux", "test id mux-demux"); SetupArgDescriptions(d.release()); }
void CTest::x_TestSeverity() { SetDiagPostLevel(eDiag_Info); SetDiagFilter(eDiagFilter_All, "[Error]module [Info]!module"); LOG_POST(Warning << MDiagModule("module") << "Test error 1"); LOG_POST(Error << MDiagModule("module") << "Test error 2"); LOG_POST(Warning << MDiagModule("module2") << "Test error 3"); LOG_POST(Info << MDiagModule("module3") << "Test error 4"); }
bool CTestRegApp::TestApp_Init(void) { LOG_POST("Testing NCBITIME " + NStr::UIntToString(s_NumThreads) + " threads..."); // Set err.-posting and tracing to maximum SetDiagTrace(eDT_Enable); SetDiagPostFlag(eDPF_All); SetDiagPostLevel(eDiag_Info); return true; }
int CBam2GraphApp::Run(void) { SetDiagPostLevel(eDiag_Info); // Get arguments const CArgs& args = GetArgs(); if ( args["file"] ) { ProcessFile(args["file"].AsString()); } else if ( args["srz"] ) { ProcessSrz(args["srz"].AsString()); } return 0; }
static bool ReadCD(const string& filename, CCdd *cdd) { // try to decide if it's binary or ascii auto_ptr<CNcbiIstream> inStream(new CNcbiIfstream(filename.c_str(), IOS_BASE::in | IOS_BASE::binary)); if (!(*inStream)) { ERROR_MESSAGE_CL("Cannot open file '" << filename << "' for reading"); return false; } string firstWord; *inStream >> firstWord; bool isBinary = !(firstWord == "Cdd"); inStream->seekg(0); // rewind file firstWord.erase(); string err; EDiagSev oldLevel = SetDiagPostLevel(eDiag_Fatal); // ignore all but Fatal errors while reading data bool readOK = ReadASNFromFile(filename.c_str(), cdd, isBinary, &err); SetDiagPostLevel(oldLevel); if (!readOK) ERROR_MESSAGE_CL("can't read input file: " << err); return readOK; }
void CTestRangeMap::Init(void) { SetDiagPostLevel(eDiag_Warning); auto_ptr<CArgDescriptions> d(new CArgDescriptions); d->SetUsageContext("testrangemap", "test different interval search classes"); d->AddDefaultKey("t", "type", "type of container to use", CArgDescriptions::eString, "CIntervalTree"); d->SetConstraint("t", (new CArgAllow_Strings)-> Allow("CIntervalTree")->Allow("i")-> Allow("CRangeMap")->Allow("r")); d->AddDefaultKey("c", "count", "how may times to run whole test", CArgDescriptions::eInteger, "1"); d->AddFlag("s", "silent operation - do not print log"); d->AddFlag("ps", "print total number of intervals"); d->AddFlag("psn", "print total number of scanned intervals"); d->AddDefaultKey("n", "rangeNumber", "number of intervals to use", CArgDescriptions::eInteger, "10000"); d->AddDefaultKey("l", "length", "length of whole region", CArgDescriptions::eInteger, "1000"); d->AddDefaultKey("il", "intervalLength", "max length of intervals to use", CArgDescriptions::eInteger, "20") ; d->AddDefaultKey("ss", "scanStep", "step of scan intervals", CArgDescriptions::eInteger, "10"); d->AddDefaultKey("sl", "scanLength", "length of scan intervals", CArgDescriptions::eInteger, "20"); d->AddDefaultKey("sc", "scanCount", "how may times to run scan test", CArgDescriptions::eInteger, "1"); SetupArgDescriptions(d.release()); }
void CTest::Init(void) { SetDiagPostLevel(eDiag_Error); // To see all output, uncomment next line: //SetDiagPostLevel(eDiag_Trace); // Create command-line argument descriptions unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), "Test compression library"); arg_desc->AddDefaultPositional ("lib", "Compression library to test", CArgDescriptions::eString, "all"); arg_desc->SetConstraint ("lib", &(*new CArgAllow_Strings, "all", "z", "bz2", "lzo")); SetupArgDescriptions(arg_desc.release()); }
void CTestApp::Init(void) { SetDiagPostLevel(eDiag_Warning); SetDiagPostFlag(eDPF_All); auto_ptr<CArgDescriptions> d(new CArgDescriptions); d->SetUsageContext("test_strdbl", "test string <-> double conversion"); d->AddFlag("speed", "Run conversion speed benchmark"); d->AddOptionalKey("precision", "precision", "Run conversion precision benchmark", CArgDescriptions::eString); d->SetConstraint("precision", &(*new CArgAllow_Strings, "Posix", "PosixOld", "strtod")); d->AddDefaultKey("count", "count", "Number of test iterations to run", CArgDescriptions::eInteger, "1000000"); d->AddOptionalKey("test_strings", "test_strings", "List of test strings to run", CArgDescriptions::eString); d->AddDefaultKey("verbose", "verbose", "Verbose level", CArgDescriptions::eInteger, "0"); d->AddDefaultKey("threshold", "threshold", "Close match threshold", CArgDescriptions::eDouble, "0.01"); d->AddFlag("randomize", "Randomize test data (for precision and double-to-string tests)"); d->AddOptionalKey("seed", "Randomization", "Randomization seed value", CArgDescriptions::eInt8); d->AddDefaultKey("digits", "significantDigits", "The number of significant digits in double-to-string conversion", CArgDescriptions::eInteger, NStr::NumericToString(DBL_DIG)); d->SetConstraint("digits", new CArgAllow_Integers(1, DBL_DIG)); d->AddDefaultKey("mode", "testmode", "Test string-to-doube, or double-to-string", CArgDescriptions::eString, "both"); d->SetConstraint( "mode", &(*new CArgAllow_Strings, "str2dbl", "dbl2str", "both")); SetupArgDescriptions(d.release()); }
void Cn3DNoWin::Init(void) { // turn off some Mesa-related env vars, irrelevant to off-screen rendering and not platform-indepdendent setenv("MESA_NO_3DNOW", "true", 1); setenv("MESA_NO_SSE", "true", 1); // setup the diagnostic stream SetDiagHandler(DisplayDiagnostic, NULL, NULL); SetDiagPostLevel(eDiag_Info); // report all messages SetDiagTrace(eDT_Default); // trace messages only when DIAG_TRACE env. var. is set UnsetDiagTraceFlag(eDPF_Location); #ifdef _DEBUG SetDiagPostFlag(eDPF_File); SetDiagPostFlag(eDPF_Line); #else UnsetDiagTraceFlag(eDPF_File); UnsetDiagTraceFlag(eDPF_Line); #endif // C++ object verification CSerialObject::SetVerifyDataGlobal(eSerialVerifyData_Always); CObjectIStream::SetVerifyDataGlobal(eSerialVerifyData_Always); CObjectOStream::SetVerifyDataGlobal(eSerialVerifyData_Always); // set up argument processing CArgDescriptions *argDescr = new CArgDescriptions(false); argDescr->SetUsageContext(GetArguments().GetProgramName(), "No-Window Cn3D"); // get data from file or network argDescr->AddOptionalKey("f", "file", "Ncbi-mime-asn1, Biostruc, or Cdd ASN.1 data file", argDescr->eString); argDescr->AddOptionalKey("d", "id", "MMDB or PDB ID", argDescr->eString); // model, for network or Biostruc load argDescr->AddOptionalKey("o", "model", "Model type to use for coordinates", argDescr->eString); argDescr->SetConstraint("o", (new CArgAllow_Strings)->Allow("alpha")->Allow("single")->Allow("PDB")); // controls for output argDescr->AddKey("p", "pngfile", "Output PNG file name", argDescr->eString); argDescr->AddKey("w", "width", "Output width in pixels", argDescr->eInteger); argDescr->AddKey("h", "height", "Output height in pixels", argDescr->eInteger); argDescr->AddFlag("i", "Create interlaced PNG"); // use favorite style argDescr->AddOptionalKey("s", "style", "Favorite style", argDescr->eString); SetupArgDescriptions(argDescr); }
int CVecScreenApp::Run(void) { int status = BLAST_EXIT_SUCCESS; try { // Allow the fasta reader to complain on invalid sequence input SetDiagPostLevel(eDiag_Warning); const bool kIsProtein(false); /*** Process the command line arguments ***/ const CArgs& args = GetArgs(); const string kDbName(args[kArgDb].AsString()); CRef<CBlastOptionsHandle> opts_hndl(CBlastOptionsFactory::Create(eVecScreen)); /*** Initialize the scope ***/ SDataLoaderConfig dlconfig(kDbName, kIsProtein); dlconfig.OptimizeForWholeLargeSequenceRetrieval(); CBlastInputSourceConfig iconfig(dlconfig); iconfig.SetQueryLocalIdMode(); CRef<CScope> scope = CBlastScopeSource(dlconfig).NewScope(); /*** Initialize the input stream ***/ CBlastFastaInputSource fasta(args[kArgQuery].AsInputFile(), iconfig); CBlastInput input(&fasta, 1); /*** Get the formatting options ***/ const CVecscreenRun::CFormatter::TOutputFormat kFmt = args[kArgOutputFormat].AsInteger(); const bool kHtmlOutput = !args["text_output"].AsBoolean(); /*** Process the input ***/ while ( !input.End() ) { CRef<CBlastQueryVector> query_batch(input.GetNextSeqBatch(*scope)); _ASSERT(query_batch->Size() == 1); CRef<IQueryFactory> queries(new CObjMgr_QueryFactory(*query_batch)); CVecscreenRun vs(CRef<CSeq_loc>(const_cast<CSeq_loc*>(&*query_batch->GetQuerySeqLoc(0))), query_batch->GetScope(0), kDbName); CVecscreenRun::CFormatter vs_format(vs, *scope, kFmt, kHtmlOutput); vs_format.FormatResults(args[kArgOutput].AsOutputFile(), opts_hndl); } } CATCH_ALL(status) return status; }
void CTestNetScheduleClient::Init(void) { InitOutputBuffer(); CONNECT_Init(); SetDiagPostFlag(eDPF_Trace); SetDiagPostLevel(eDiag_Info); // Setup command line arguments and parameters // Create command-line argument descriptions class auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); // Specify USAGE context arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), "NetSchedule client"); arg_desc->AddKey("service", "ServiceName", "NetSchedule service name (format: host:port or servcie_name)", CArgDescriptions::eString); arg_desc->AddKey("queue", "QueueName", "NetSchedule queue name", CArgDescriptions::eString); arg_desc->AddOptionalKey("ilen", "InputLength", "Average input length", CArgDescriptions::eInteger); arg_desc->AddOptionalKey("maxruntime", "MaxRunTime", "Maximum run time of this test", CArgDescriptions::eInteger); arg_desc->AddOptionalKey("input", "InputString", "Input string", CArgDescriptions::eString); arg_desc->AddOptionalKey("jobs", "jobs", "Number of jobs to submit", CArgDescriptions::eInteger); arg_desc->AddOptionalKey("naff", "AffinityTokens", "Number of different affinities", CArgDescriptions::eInteger); // Setup arg.descriptions for this application SetupArgDescriptions(arg_desc.release()); }
bool CCSRATestApp::TestApp_Init(void) { SetDiagPostLevel(eDiag_Info); const CArgs& args = GetArgs(); m_Verbose = args["verbose"]; m_ErrorCount = 0; m_Seed = args["seed"]? args["seed"].AsInteger(): int(time(0)); if ( m_Verbose ) { LOG_POST(Info<<"Seed: "<<m_Seed); } NStr::Split(args["accs"].AsString(), ",", m_Accession); if ( args["accs-file"] ) { m_Accession.clear(); CNcbiIstream& in = args["accs-file"].AsInputFile(); string acc; while ( in >> acc ) { m_Accession.push_back(acc); } } if ( m_Accession.empty() ) { ERR_POST(Fatal<<"empty accession list"); } m_IterCount = args["iter-count"].AsInteger(); m_IterSize = args["iter-size"].AsInteger(); m_MaxSpotId.assign(m_Accession.size(), 0); m_OM = CObjectManager::GetInstance(); CCSRADataLoader::RegisterInObjectManager(*m_OM, CObjectManager::eDefault); if ( args["shared-scope"] ) { m_SharedScope = new CScope(*m_OM); m_SharedScope->AddDefaults(); } m_ResetHistory = args["reset-history"]; m_TestRefSeqs = args["reference-sequences"]; m_FullSeq = args["full-seq"]; if ( m_TestRefSeqs ) { LoadRefSeqs(); } if ( args["preload"] ) { Thread_Run(-1); } return true; }
int CBamGraphTestApp::Run(void) { SetDiagPostLevel(eDiag_Info); // Get arguments const CArgs& args = GetArgs(); vector<string> dirs; if ( args["dir"] ) { dirs.push_back(args["dir"].AsString()); } else { vector<string> reps; NStr::Tokenize(NCBI_TEST_BAM_FILE_PATH, ":", reps); ITERATE ( vector<string>, it, reps ) { dirs.push_back(CFile::MakePath(*it, BAM_DIR1)); dirs.push_back(CFile::MakePath(*it, BAM_DIR2)); dirs.push_back(CFile::MakePath(*it, BAM_DIR3)); dirs.push_back(CFile::MakePath(*it, BAM_DIR4)); } }
int Run(void) { CONNECT_Init(&CNcbiApplication::Instance()->GetConfig()); const CNcbiArguments& app_args = GetArguments(); m_Seed = app_args.Size() > 1 ? (unsigned int)atoi(app_args[1].c_str()) : (unsigned int)time(0); // Set error posting and tracing on maximum SetDiagTrace(eDT_Enable); SetDiagPostLevel(eDiag_Info); SetDiagPostAllFlags(SetDiagPostAllFlags(eDPF_Default) | eDPF_All | eDPF_OmitInfoSev); UnsetDiagPostFlag(eDPF_Line); UnsetDiagPostFlag(eDPF_File); UnsetDiagPostFlag(eDPF_Location); UnsetDiagPostFlag(eDPF_LongFilename); SetDiagTraceAllFlags(SetDiagPostAllFlags(eDPF_Default)); string host = "www.ncbi.nlm.nih.gov"; string path = "/Service/bounce.cgi"; string args = kEmptyStr; string uhdr = kEmptyStr; ERR_POST(Info << "Seed = " << m_Seed); srand(m_Seed); ERR_POST(Info << "Creating HTTP connection to " "http://" + host + path + &"?"[args.empty() ? 1 : 0] + args); CConn_HttpStream ios(host, path, args, uhdr); int n = TEST_StreamPushback(ios, false/*no rewind*/); // Manual CONNECT_UnInit (for implicit CONNECT_Init() by HTTP stream ctor) CORE_SetREG(0); CORE_SetLOG(0); CORE_SetLOCK(0); return n; }
void CTestApplication::Init(void) { // Set error posting and tracing on maximum SetDiagTrace(eDT_Enable); SetDiagPostFlag(eDPF_All); SetDiagPostLevel(eDiag_Info); // Create command-line argument descriptions class auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); // Specify USAGE context arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), "Test inter-process locks"); // Specific to multi-process configuration test arg_desc->AddDefaultKey("test", "number", "test case number (internal use only)", CArgDescriptions::eInteger, "0"); arg_desc->AddDefaultKey("lock", "name", "parent's lock (internal use only)", CArgDescriptions::eString, kEmptyStr); // Setup arg.descriptions for this application SetupArgDescriptions(arg_desc.release()); }
void CDBAPI_CacheAdmin::Init(void) { SetDiagPostLevel(eDiag_Warning); SetDiagPostFlag(eDPF_File); SetDiagPostFlag(eDPF_Line); unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), "DBAPI cache admin library"); arg_desc->AddDefaultKey("s", "server", "Database server name (default: MSSQL10)", CArgDescriptions::eString, "MSSQL10"); arg_desc->AddDefaultKey("d", "database", "Database name (default: NCBI_Cache)", CArgDescriptions::eString, "NCBI_Cache"); arg_desc->AddDefaultKey("u", "username", "Login name (default: cwrite)", CArgDescriptions::eString, "cwrite"); arg_desc->AddDefaultKey("p", "password", "Password", CArgDescriptions::eString, "allowed"); arg_desc->AddFlag("m", "Run cache maintenance (Timeout based BLOB removal)."); arg_desc->AddDefaultKey("st", "stimeout", "BLOB expiration timeout in seconds", CArgDescriptions::eInteger, "0"); arg_desc->AddDefaultKey("mt", "mtimeout", "BLOB expiration timeout in minutes", CArgDescriptions::eInteger, "0"); arg_desc->AddDefaultKey("ht", "htimeout", "BLOB expiration timeout in hours", CArgDescriptions::eInteger, "0"); arg_desc->AddDefaultKey("dt", "dtimeout", "BLOB expiration timeout in days", CArgDescriptions::eInteger, "0"); SetupArgDescriptions(arg_desc.release()); }
int CAlignmentRefiner::Run(void) { CCdd cdd; unsigned int alWidth; unsigned int nBlocksFromAU; string message; // Get arguments CArgs args = GetArgs(); string fname, err; string basename = args["o"].AsString() + "_", suffix = ".cn3"; // Stream to results file, if provided, or cout // (NOTE: "x_lg" is just a workaround for bug in SUN WorkShop 5.1 compiler) ostream* x_lg = args["details"] ? &args["details"].AsOutputFile() : &cout; ostream& detailsStream = *x_lg; SetDiagStream(x_lg); // send all diagnostic messages to the same stream // Set to info level here, not in main, to avoid info messages about missing log files. SetDiagPostLevel(eDiag_Info); // Set up details stream first... if (args["details"]) { string str; detailsStream << args.Print(str) << endl << endl; detailsStream << string(72, '=') << endl; detailsStream.precision(2); // if (args["qd"]) m_quietDetails = true; } // Get initial alignment (in a Cdd blob) from the input file; // convert to an AlignmentUtility object. if (!ReadCD(args["i"].AsString(), &cdd)) { ERROR_MESSAGE_CL("error reading CD from input file " << args["i"].AsString()); return eRefinerResultCantReadCD; } AlignmentUtility* au = new AlignmentUtility(cdd.GetSequences(), cdd.GetSeqannot()); const BlockMultipleAlignment* bma = (au && au->Okay()) ? au->GetBlockMultipleAlignment() : NULL; if (!bma) { delete au; ERROR_MESSAGE_CL("Found invalid alignment in CD " << args["i"].AsString()); return eRefinerResultAlignmentUtilityError; } nBlocksFromAU = bma->NAlignedBlocks(); alWidth = bma->AlignmentWidth(); TERSE_INFO_MESSAGE_CL("\nRows in alignment: " << bma->NRows()); TERSE_INFO_MESSAGE_CL("Alignment width : " << alWidth); TERSE_INFO_MESSAGE_CL("Number of Aligned Blocks after IBM: " << nBlocksFromAU << "\n"); // Some general parameters... m_nTrials = (unsigned) args["n"].AsInteger(); m_nCycles = args["nc"].AsInteger(); m_scoreDeviationThreshold = args["convScoreChange"].AsDouble(); m_quietMode = (args["q"]); // if (m_quietMode) SetDiagPostLevel(eDiag_Error); // Fill out data structure for leave-one-out parameters // LOO is performed unless -no_LOO option used RefinerResultCode looParamResult = ExtractLOOArgs(nBlocksFromAU, message); if (looParamResult != eRefinerResultOK) { ERROR_MESSAGE_CL(message); return looParamResult; } // If using a fixed selection order based on row-scores of the // initial alignment, no need to do multiple trials. if (m_nTrials > 1 && m_loo.selectorCode != eRandomSelectionOrder) { m_nTrials = 1; WARNING_MESSAGE_CL("For deterministic row-selection order, multiple trials are redundant.\nSetting number of trials to one and continuing.\n"); } //EchoSettings(detailsStream, true, false); // Fill out data structure for block editing parameters. // By default, edit blocks -- must explicitly skip with the -be_fix option. RefinerResultCode beParamResult = ExtractBEArgs(nBlocksFromAU, message); if (beParamResult != eRefinerResultOK) { ERROR_MESSAGE_CL(message); return beParamResult; } //EchoSettings(detailsStream, false, true); EchoSettings(detailsStream, true, true); if (!m_blockEdit.editBlocks && !m_loo.doLOO) { ERROR_MESSAGE_CL("Nothing will happen as both LOO and block editing have been disabled. Stopping"); return eRefinerResultInconsistentArgumentCombination; } // Perform the refinement... TRACE_MESSAGE_CL("Entering refiner engine...\n"); CBMARefinerEngine refinerEngine(m_loo, m_blockEdit, m_nCycles, m_nTrials, true, !m_quietMode, m_scoreDeviationThreshold); RefinerResultCode result = refinerEngine.Refine(au, &detailsStream); // Output final statistics and refined alignments // Get results from all trials; use reverse iterator to get them // out of the map in order of highest to lowest score. unsigned int n = 0; unsigned int trial; unsigned int nToWrite = (m_nTrials > 1) ? args["nout"].AsInteger() : 1; const RefinedAlignments& optimizedAlignments = refinerEngine.GetAllResults(); RefinedAlignmentsRevCIt rcit = optimizedAlignments.rbegin(), rend = optimizedAlignments.rend(); if (rcit != rend) { detailsStream << endl << endl << "Original Alignment Score = " << refinerEngine.GetInitialScore() << endl; detailsStream << endl << "Best Refined Alignments (in descending score order)\n\n"; } else { detailsStream << endl << "No Refined Alignments found (?)\n\n"; } for (; rcit != rend; ++rcit, ++n) { trial = rcit->second.iteration; if (rcit->second.au == NULL) { detailsStream << "Problem in trial " << trial << " -> no refined alignment available." << endl << endl; continue; } detailsStream << "Alignment " << n << ": Score = " << rcit->first << " (trial " << trial << ")" << endl; if (n < nToWrite) { err.erase(); cdd.SetSeqannot() = rcit->second.au->GetSeqAnnots(); // write output as a CD in a new file fname = basename + NStr::UIntToString(n) + "_trial" + NStr::UIntToString(trial) + suffix; detailsStream << " (written to file '" << fname << "')"; if (!WriteASNToFile(fname.c_str(), cdd, args["ob"].HasValue(), &err)) { ERROR_MESSAGE_CL("error writing output file " << fname); } } detailsStream << endl; } // Destructor of RefinerEngine cleans up map of optimized alignments // once it goes out of scope. // delete au; // delete auOriginal; if (args["details"]) args["details"].CloseFile(); return result; }
END_NCBI_SCOPE int main(int argc, char* argv[]) { USING_NCBI_SCOPE; SetDiagTrace(eDT_Enable); SetDiagPostLevel(eDiag_Info); SetDiagPostAllFlags(eDPF_DateTime | eDPF_Severity | eDPF_OmitInfoSev | eDPF_ErrorID); ERR_POST(Info << "Testing NCBI CRWStream API"); int seed; if (argc == 2) { seed = atoi(argv[1]); ERR_POST(Info << "Reusing SEED " << seed); } else { seed = (int(CProcess::GetCurrentPid()) ^ int(CTime(CTime::eCurrent).GetTimeT())); ERR_POST(Info << "Using SEED " << seed); } srand(seed); unsigned char* hugedata = new unsigned char[kHugeBufsize * 3]; ERR_POST(Info << "Generating data: " << kHugeBufsize << " random bytes"); for (size_t n = 0; n < kHugeBufsize; n += 2) { hugedata[n] = (unsigned char)(rand() & 0xFF); hugedata[n + 1] = (unsigned char)(rand() & 0xFF); hugedata[n + kHugeBufsize] = (unsigned char) 0xDE; hugedata[n + kHugeBufsize + 1] = (unsigned char) 0xAD; hugedata[n + kHugeBufsize*2] = (unsigned char) 0xBE; hugedata[n + kHugeBufsize*2 + 1] = (unsigned char) 0xEF; } ERR_POST(Info << "Pumping data with random I/O"); CMyReader* rd = new CMyReader(hugedata, kHugeBufsize); CMyWriter* wr = new CMyWriter(hugedata + kHugeBufsize, kHugeBufsize); CRStream is(rd, kReadBufsize, 0, CRWStreambuf::fOwnReader); CWStream os(wr, kWriteBufsize, 0, CRWStreambuf::fOwnWriter); char* buf = new char[kMaxIOSize]; size_t n_in = 0, n_out = 0; do { size_t x_in = rand() % kMaxIOSize + 1; ERR_POST(Info << "Read: " << setw(8) << x_in); is.read(buf, x_in); if (!(x_in = (size_t) is.gcount())) break; n_in += x_in; size_t x_out = 0; while (x_out < x_in) { size_t xx_out = rand() % (x_in - x_out) + 1; ERR_POST(Info << "Write: " << setw(8) << xx_out << '/' << x_out << '+' << (x_in - x_out)); if (!os.write(buf + x_out, xx_out)) break; x_out += xx_out; } if (x_out < x_in) break; n_out += x_out; } while (is.good()); os.flush(); delete[] buf; ERR_POST(Info << "Read: " << setw(8) << n_in << '/' << kHugeBufsize << "; position: " << rd->GetPosition() << '/' << rd->GetSize()); ERR_POST(Info << "Write: " << setw(8) << n_out << '/' << kHugeBufsize << "; position: " << wr->GetPosition() << '/' << wr->GetSize()); _ASSERT(kHugeBufsize == n_in && kHugeBufsize == rd->GetSize() && kHugeBufsize == rd->GetPosition()); _ASSERT(kHugeBufsize == n_out && kHugeBufsize == wr->GetSize() && kHugeBufsize == wr->GetPosition()); ERR_POST(Info << "Comparing original with collected data"); for (size_t n = 0; n < kHugeBufsize; n++) { if (hugedata[n] != hugedata[n + kHugeBufsize]) ERR_POST(Fatal << "Mismatch @ " << n); } ERR_POST(Info << "Checking tied I/O"); buf = (char*) hugedata + kHugeBufsize; memset(buf, '\xFF', kHugeBufsize); CMyReaderWriter* rw = new CMyReaderWriter(hugedata + kHugeBufsize, kHugeBufsize); CRWStream io(rw, 2*(kReadBufsize + kWriteBufsize), 0, CRWStreambuf::fOwnReader); n_out = n_in = 0; do { if ((rand() % 10 == 2 || n_out == n_in) && n_out < kHugeBufsize) { size_t x_out = rand() % kMaxIOSize + 1; if (x_out + n_out > kHugeBufsize) x_out = kHugeBufsize - n_out; ERR_POST(Info << "Write: " << setw(8) << x_out); if (!io.write(buf - kHugeBufsize + n_out, x_out)) break; n_out += x_out; } if (rand() % 10 == 4 && n_out > n_in) { size_t x_in = (rand() & 1 ? n_out - n_in : rand() % (n_out - n_in) + 1); ERR_POST(Info << "Read: " << setw(8) << x_in); if (!io.read(buf + kHugeBufsize + n_in, x_in)) break; n_in += x_in; } if (n_out >= kHugeBufsize && n_in >= kHugeBufsize) break; } while (io.good()); // io.flush(); // not needed as everything should have been read out ERR_POST(Info << "Read: " << setw(8) << n_in << '/' << kHugeBufsize << "; " << "position: " << rw->GetRPosition() << '/' << rw->GetRSize()); ERR_POST(Info << "Write: " << setw(8) << n_out << '/' << kHugeBufsize << "; " << "position: " << rw->GetWPosition() << '/' << rw->GetWSize()); _ASSERT(kHugeBufsize == n_in && kHugeBufsize == rw->GetRSize() && kHugeBufsize == rw->GetRPosition()); _ASSERT(kHugeBufsize == n_out && kHugeBufsize == rw->GetWSize() && kHugeBufsize == rw->GetWPosition()); ERR_POST(Info << "Comparing original with collected data"); for (size_t n = 0; n < kHugeBufsize; n++) { if (hugedata[n] != hugedata[n + kHugeBufsize] || hugedata[n] != hugedata[n + kHugeBufsize*2]) { ERR_POST(Fatal << "Mismatch @ " << n); } } ERR_POST(Info << "Test completed successfully"); delete[] hugedata; return 0; }
void CTest::Init(void) { SetDiagPostLevel(eDiag_Warning); }
//------------------------------------------------------------------------- int CWinMaskApplication::Run (void) { SetDiagPostLevel( eDiag_Warning ); CWinMaskConfig aConfig( GetArgs() ); // Branch away immediately if the converter is called. // // if( GetArgs()["convert"].AsBoolean() ) { if( aConfig.AppType() == CWinMaskConfig::eConvertCounts ) { if( aConfig.Output() == "-" ) { CWinMaskCountsConverter converter( aConfig.Input(), NcbiCout, aConfig.SFormat(), aConfig.GetMetaData() ); return converter(); } else { CWinMaskCountsConverter converter( aConfig.Input(), aConfig.Output(), aConfig.SFormat(), aConfig.GetMetaData() ); return converter(); } } CRef<CObjectManager> om(CObjectManager::GetInstance()); if(aConfig.InFmt() == "seqids") CGBDataLoader::RegisterInObjectManager( *om, 0, CObjectManager::eDefault ); // Read and validate configuration values. if( aConfig.AppType() == CWinMaskConfig::eComputeCounts ) { if( aConfig.Output() == "-" ) { CWinMaskCountsGenerator cg( aConfig.Input(), NcbiCout, aConfig.InFmt(), aConfig.SFormat(), aConfig.Th(), aConfig.Mem(), aConfig.UnitSize(), aConfig.GenomeSize(), aConfig.MinScore(), aConfig.MaxScore(), aConfig.CheckDup(), aConfig.FaList(), aConfig.Ids(), aConfig.ExcludeIds(), aConfig.UseBA(), aConfig.GetMetaData() ); cg(); } else { CWinMaskCountsGenerator cg( aConfig.Input(), aConfig.Output(), aConfig.InFmt(), aConfig.SFormat(), aConfig.Th(), aConfig.Mem(), aConfig.UnitSize(), aConfig.GenomeSize(), aConfig.MinScore(), aConfig.MaxScore(), aConfig.CheckDup(), aConfig.FaList(), aConfig.Ids(), aConfig.ExcludeIds(), aConfig.UseBA(), aConfig.GetMetaData() ); cg(); } return 0; } if(aConfig.InFmt() == "seqids"){ LOG_POST(Error << "windowmasker with seqids input not implemented yet"); return 1; } CMaskReader & theReader = aConfig.Reader(); CMaskWriter & theWriter = aConfig.Writer(); CSeqMasker theMasker( aConfig.LStatName(), aConfig.WindowSize(), aConfig.WindowStep(), aConfig.UnitStep(), aConfig.Textend(), aConfig.CutoffScore(), aConfig.MaxScore(), aConfig.MinScore(), aConfig.SetMaxScore(), aConfig.SetMinScore(), aConfig.MergePass(), aConfig.MergeCutoffScore(), aConfig.AbsMergeCutoffDist(), aConfig.MeanMergeCutoffDist(), aConfig.MergeUnitStep(), aConfig.Trigger(), aConfig.TMin_Count(), aConfig.Discontig(), aConfig.Pattern(), aConfig.UseBA() ); CRef< CSeq_entry > aSeqEntry( 0 ); Uint4 total = 0, total_masked = 0; CSDustMasker * duster( 0 ); const CWinMaskConfig::CIdSet * ids( aConfig.Ids() ); const CWinMaskConfig::CIdSet * exclude_ids( aConfig.ExcludeIds() ); if( aConfig.AppType() == CWinMaskConfig::eGenerateMasksWithDuster ) duster = new CSDustMasker( aConfig.DustWindow(), aConfig.DustLevel(), aConfig.DustLinker() ); while( (aSeqEntry = theReader.GetNextSequence()).NotEmpty() ) { if( aSeqEntry->Which() == CSeq_entry::e_not_set ) continue; CScope scope(*om); CSeq_entry_Handle seh = scope.AddTopLevelSeqEntry(*aSeqEntry); Uint4 masked = 0; CBioseq_CI bs_iter(seh, CSeq_inst::eMol_na); for ( ; bs_iter; ++bs_iter) { CBioseq_Handle bsh = *bs_iter; if (bsh.GetBioseqLength() == 0) { continue; } if( CWinMaskUtil::consider( bsh, ids, exclude_ids ) ) { TSeqPos len = bsh.GetBioseqLength(); total += len; _TRACE( "Sequence length " << len ); CSeqVector data = bsh.GetSeqVector(CBioseq_Handle::eCoding_Iupac); auto_ptr< CSeqMasker::TMaskList > mask_info( theMasker( data ) ); CSeqMasker::TMaskList dummy; if( duster != 0 ) // Dust and merge with mask_info { auto_ptr< CSeqMasker::TMaskList > dust_info( (*duster)( data, *mask_info.get() ) ); CSeqMasker::MergeMaskInfo( mask_info.get(), dust_info.get() ); } // theWriter.Print( bsh, *mask_info, aConfig.MatchId() ); theWriter.Print( bsh, *mask_info, GetArgs()["parse_seqids"] ); for( CSeqMasker::TMaskList::const_iterator i = mask_info->begin(); i != mask_info->end(); ++i ) masked += i->second - i->first + 1; total_masked += masked; _TRACE( "Number of positions masked: " << masked ); } } } _TRACE( "Total number of positions: " << total ); _TRACE( "Total number of positions masked: " << total_masked ); return 0; }