CWinMaskUtil::CInputBioseq_CI& CWinMaskUtil::CInputBioseq_CI::operator++ (void) { m_Scope.Reset(new CScope(*CObjectManager::GetInstance())); m_Scope->AddDefaults(); m_CurrentBioseq.Reset(); if(m_Reader.get()){ CRef<CSeq_entry> next_entry = m_Reader->GetNextSequence(); if( next_entry.NotEmpty() ){ NCBI_ASSERT(next_entry->IsSeq(), "Reader returned bad entry"); m_CurrentBioseq = m_Scope->AddTopLevelSeqEntry(*next_entry).GetSeq(); } } else { // No reader; this means input is a list of gis, one per line string id; while (NcbiGetlineEOL(*m_InputFile, id)) { if(id.empty() || id[0] == '#') continue; m_CurrentBioseq = m_Scope->GetBioseqHandle(CSeq_id_Handle::GetHandle(id)); break; } } return *this; }
void CSimpleDictionary::Read(CNcbiIstream& istr) { string line; string metaphone; string word; while (NcbiGetlineEOL(istr, line)) { string::size_type pos = line.find_first_of("|"); if (pos == string::npos) { word = line; CDictionaryUtil::GetMetaphone(word, &metaphone, m_MetaphoneKeySize); } else { metaphone = line.substr(0, pos); word = line.substr(pos + 1, line.length() - pos - 1); } // insert forward and reverse dictionary pairings m_ForwardDict.insert(m_ForwardDict.end(), word); TStringSet& word_set = m_ReverseDict[metaphone]; word_set.insert(word_set.end(), word); } }
CDBInterfacesFileConnParams::CDBInterfacesFileConnParams( const CDBConnParams& other, const string& file ) : CDBConnParamsDelegate(other) { string file_name; if (!file.empty() && CFile(file).Exists()) { file_name = file; } else { const CNcbiEnvironment env; // Get it from a default place ... file_name = env.Get("SYBASE") + "/interfaces"; if (!CFile(file_name).Exists()) { file_name = env.Get("HOME") + "/.interfaces"; if (!CFile(file_name).Exists()) { return; } } } CNcbiIfstream istr(file_name.c_str()); if (!istr) { return; } string line; string key; string host_str; string port_str; vector<string> arr_param; enum EState {eInitial, eKeyRead, eValueRead}; EState state = eInitial; bool tli_format = false; while (NcbiGetlineEOL(istr, line)) { if (line[0] == '#' || line.empty()) { continue; } else if (line[0] == '\t') { if (state == eKeyRead) { NStr::TruncateSpacesInPlace(line); arr_param.clear(); NStr::Tokenize(line, "\t ", arr_param); if (NStr::Equal(arr_param[0], "query")) { if (NStr::Equal(arr_param[1], "tli")) { tli_format = true; const string tli_str = arr_param[arr_param.size() - 1]; host_str = tli_str.substr(10 - 1, 8); port_str = tli_str.substr(6 - 1, 4); } else { host_str = arr_param[arr_param.size() - 2]; port_str = arr_param[arr_param.size() - 1]; } state = eValueRead; } } else { // Skip all values except the first one ... continue; } } else { if (state == eInitial) { key = line; NStr::TruncateSpacesInPlace(key); state = eKeyRead; } else { // Error ... DATABASE_DRIVER_ERROR("Invalid interfaces file line: " + line, 20001); } } if (state == eValueRead) { Uint4 host = 0; unsigned char* b = (unsigned char*) &host; if (!host_str.empty() && !port_str.empty()) { if (tli_format) { b[0] = NStr::StringToUInt(host_str.substr(0, 2), 0, 16); b[1] = NStr::StringToUInt(host_str.substr(2, 2), 0, 16); b[2] = NStr::StringToUInt(host_str.substr(4, 2), 0, 16); b[3] = NStr::StringToUInt(host_str.substr(6, 2), 0, 16); m_Records[key] = SIRecord(host, NStr::StringToUInt(port_str, 0, 16)); } else { NStr::TruncateSpacesInPlace(host_str); arr_param.clear(); NStr::Tokenize(host_str, ".", arr_param); b[0] = NStr::StringToUInt(arr_param[0]); b[1] = NStr::StringToUInt(arr_param[1]); b[2] = NStr::StringToUInt(arr_param[2]); b[3] = NStr::StringToUInt(arr_param[3]); m_Records[key] = SIRecord(host, NStr::StringToUInt(port_str)); } } state = eInitial; } } }
// run a test void s_RunTest(const string &sTestName, const STestInfo & testInfo) { CAgpToSeqEntry::TFlags fFlags = 0; // adjust flags based on whatever's in the flags file if( ! testInfo.m_FlagFile.GetPath().empty() ) { CNcbiIfstream flagfile( testInfo.m_FlagFile.GetPath().c_str() ); BOOST_CHECK(flagfile); while( flagfile ) { string sLine; NcbiGetlineEOL(flagfile, sLine); NStr::TruncateSpacesInPlace(sLine); if( sLine.empty() ) { // ignore blank lines } else if( sLine == "fForceLocalId" ) { // make sure flag not already set BOOST_CHECK(0 == (fFlags & CAgpToSeqEntry::fForceLocalId)); fFlags |= CAgpToSeqEntry::fForceLocalId; } else if( sLine == "fSetSeqGap" ) { BOOST_CHECK(0 == (fFlags & CAgpToSeqEntry::fSetSeqGap)); fFlags |= CAgpToSeqEntry::fSetSeqGap; } else { BOOST_ERROR("Unknown line in flags file (" << testInfo.m_FlagFile.GetPath() << "): " << sLine); } } BOOST_CHECK(flagfile.eof()); } // create the object to do the actual reading CAgpToSeqEntry agpToSeqEntry(fFlags); // read the AGP CAgpToSeqEntry::TSeqEntryRefVec seqEntryRefVec; { CNcbiIfstream agpfile(testInfo.m_AGPFile.GetPath().c_str()); BOOST_CHECK(agpfile); int iErrCode = agpToSeqEntry.ReadStream(agpfile); // in the future, we might have a file to allow us // to expect certain errors rather than assuming all errors are // bad. BOOST_CHECK_EQUAL( iErrCode, 0 ); const string sErrorMsgs = agpToSeqEntry.GetErrorHandler()->GetErrorMessage(); if( ! sErrorMsgs.empty() ) { cout << "AGP errors/warnings: " << endl; cout << "(Ignore warnings about assuming AGP version)" << endl; cout << sErrorMsgs << endl; } // swap faster than assignment, and okay in this case seqEntryRefVec.swap( agpToSeqEntry.GetResult() ); } const size_t uNumExpected = testInfo.m_vecExpectedSeqEntryFiles.size(); const size_t uNumResulted = seqEntryRefVec.size(); BOOST_CHECK_EQUAL( uNumResulted, uNumExpected ); // check the results against what was expected for( size_t idx = 0; idx < uNumResulted; ++idx ) { // the SeqEntry that we got CConstRef<CSeq_entry> pResultingSeqEntry = seqEntryRefVec[idx]; // determine what SeqEntry was expected CRef<CSeq_entry> pExpectedSeqEntry; if( idx < uNumExpected ) { CNcbiIfstream expected_seq_entry_file( testInfo.m_vecExpectedSeqEntryFiles[idx].GetPath().c_str() ); pExpectedSeqEntry.Reset( new CSeq_entry ); BOOST_CHECK_NO_THROW(expected_seq_entry_file >> MSerial_AsnText >> *pExpectedSeqEntry); } // check if same (or if none was expected here) if( pExpectedSeqEntry.IsNull() || ! pResultingSeqEntry->Equals(*pExpectedSeqEntry) ) { BOOST_ERROR("For test " << sTestName << " on index " << idx << ", the resulting seq-entry does not match " "what was expected"); cerr << "##### Resulting Seq-entry: " << endl; cerr << MSerial_AsnText << *pResultingSeqEntry << endl; } }