void combine(JKArgs& args){ string ps2t=args["ps2t"]; string pt2s=args["pt2s"]; string out=args["o"]; if(ps2t==""||pt2s==""||out=="")usage(); LexDic lex_s2t,lex_t2s; bool uselex=false; if(args.count("lex_s2t")||args.count("lex_t2s"))uselex=true; if(uselex&&lex_s2t.read(args["lex_s2t"])==false)return; if(uselex&&lex_t2s.read(args["lex_t2s"])==false)return; RichPhraseTable pt; pt.read(ps2t); ifstream is(pt2s.c_str()); for(string line; getline(is,line);){ trim(line); if(line=="")continue; vector<string> content; split_regex(content,line,regex(" => | \\|\\|\\| ")); if(content.size()<3)continue; vector<string> features; split_regex(features,content[2],regex(" ")); auto& item=pt[content[1]][content[0]]; item.pt2s=stod(features[0]); if(uselex){ vector<string> src,tgt; split(src,content[1],is_any_of(" \t")); split(tgt,content[0],is_any_of(" \t")); item.ls2t=ScoreLex(src, tgt, lex_s2t); item.lt2s=ScoreLex(tgt, src, lex_t2s); } else item.ls2t=item.lt2s=1; } pt.print(out); }
prvreader::PrvEvent* prvreader::PrvParser::parseHeader(tokenizer<escaped_list_separator<char> > *tokens) { tokenizer<escaped_list_separator<char> >::iterator tokensIterator=tokens->begin(); string temp=*tokensIterator; erase_all(temp, GENERIC_SEP); replace(temp.begin(), temp.end(), '*', ':'); prvMetaData->setComment(temp); tokensIterator++; temp=*tokensIterator; tokensIterator++; vector<string> tokensTemp; split(tokensTemp, temp, is_any_of(PRV_HEADER_SEP_DURATION)); if (tokensTemp.size()>0){ prvMetaData->setDuration(stol(tokensTemp.operator [](PRV_HEADER_SUBFIELD_DURATION_VALUE))); } if (tokensTemp.size()>1){ prvMetaData->setTimeUnit(tokensTemp[PRV_HEADER_SUBFIELD_DURATION_UNIT]); }else{ prvMetaData->setTimeUnit(""); } temp=*tokensIterator; tokensIterator++; tokensTemp.clear(); split(tokensTemp, temp, is_any_of(GENERIC_SEP)); int nodes=atoi(tokensTemp.operator [](PRV_HEADER_SUBFIELD_HW_NODES).c_str()); prvMetaData->setNodes(nodes); vector<int> * cpus = new vector<int>(); temp=tokensTemp.operator [](PRV_HEADER_SUBFIELD_HW_CPUS); split(tokensTemp, temp, is_any_of(PRV_HEADER_SEP_HW_CPUS)); for (int i=0; i<tokensTemp.size(); i++){ cpus->push_back(atoi(tokensTemp.operator [](i).c_str())); } prvMetaData->setCpus(cpus); return new PrvOther(lineNumber, prveventtype::Header); }
bool WstringToTime(const wstring& wstr, SYSTEMTIME& st) { bool fRet = false; vector<wstring> strVector, dateVector, timeVector; split(strVector, wstr, is_any_of(L" ")); if (strVector.size() != 2) goto END; split(dateVector, strVector[0], is_any_of(L"/")); if (dateVector.size() != 3) goto END; st.wYear = _wtoi(dateVector[0].c_str()); st.wMonth = _wtoi(dateVector[1].c_str()); st.wDay = _wtoi(dateVector[2].c_str()); split(timeVector, strVector[1], is_any_of(L":")); if ((timeVector.size() != 3) && (timeVector.size() != 2)) // size = 3: hh:mm:ss, size = 2: hh:mm and set ss = 0. goto END; st.wHour = _wtoi(timeVector[0].c_str()); st.wMinute = _wtoi(timeVector[1].c_str()); st.wSecond = (timeVector.size() == 3) ? _wtoi(timeVector[2].c_str()) : 0; fRet = true; END: return fRet; }
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Function Name: // Purpose: // Inputs: // Output: // Notes: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ExpressionBuilder::ExpressionBuilder(string strEquation) { string var; vector<string> fields; split(fields, strEquation, is_any_of(",")); for (vector<string>::iterator iter = fields.begin() + 1; iter != fields.end(); iter++) { double val = 0.0; vector<string> tmp; // Split the variable from it's value split(tmp, ::trim(*iter), is_any_of("=")); withVariable(::trim(tmp[0]), val = atof(::trim(tmp[1]).c_str())); m_eq_vals.push_back(val); } string expression = ::trim(fields[0]); if (expression.length() == 0) throw new IllegalArgumentException("Expression can not be empty!."); m_expression = expression; if (getenv("PROPERTY_UNARY_HIGH_PRECEDENCE")) var = getenv("PROPERTY_UNARY_HIGH_PRECEDENCE"); m_highUnaryPrecedence = (var.length() == 0 || var != "false"); getBuiltinFunctions(); getBuiltinOperators(); getValidOperators(); }
vector<string> Browser::processParams(string input, string param, int count) { vector<string> params; trim(input); string res = input.substr(param.size() + 1); // pokud mame jenom parametr, vratime vsechno za pozici if(count == 1){ // odstranime uvozovky res.erase( remove(res.begin(), res.end(), '\"' ), res.end() ); params.push_back(res); } if(count == 2){ vector<string> pieces; split(pieces, res, is_any_of("\"")); // zkusime tedy mezery if(pieces.size() != 4){ split(pieces, res, is_any_of(" ")); if(pieces.size() == 2){ params.push_back(pieces[0]); params.push_back(pieces[1]); } } if(pieces.size() == 4){ params.push_back(pieces[1]); params.push_back(pieces[3]); } } // zkontrolujeme znaky for(int i = 0; i < (int)params.size(); i++){ if(params[i] == ".") params[i] = ""; } if(params.size() != count){ cout << "Wrong number parameters" << endl; } buffer.writeLine(lexical_cast<string>(params.size())); //cout << params[0] << endl; //cout << params[1] << endl; return params; }
void castGWAS::construct(string &chrNum) { ifstream infile; string fileName = "/home/yulingl/ase_diseases/gwasCatalog/processedGWASCatalog/" + chrNum; infile.open(fileName.c_str()); vector<string> L0Info; string currentLine; while (!getline(infile, currentLine).eof()) { split(L0Info, currentLine, is_any_of("\t")); vector<string> L1Info; set<string> platformSet; split(L1Info, L0Info[5], is_any_of(",")); for (int i = 0; i < L1Info.size(); ++ i) { platformSet.insert(L1Info[i]); } if (platformSet.find("Affymetrix") != platformSet.end() || platformSet.find("Illumina") != platformSet.end()) { initial_keys.insert(L0Info[0]); GWASSNPInfo tmpInfo; tmpInfo.allelFreq = atof(L0Info[1].c_str()); if (tmpInfo.allelFreq > 0.5) { tmpInfo.allelFreq = 1 - tmpInfo.allelFreq; } tmpInfo.coord = strtoul(L0Info[2].c_str(), NULL, 0); tmpInfo.pvalue = atof(L0Info[3].c_str()); tmpInfo.function = L0Info[4]; if (platformSet.find("Affymetrix") != platformSet.end()) { tmpInfo.affymetrix = 1; } else { tmpInfo.affymetrix = 0; } if (platformSet.find("Illumina") != platformSet.end()) { tmpInfo.illumina = 1; } else { tmpInfo.illumina = 0; } key_info[L0Info[0]] = tmpInfo; } } infile.close(); }
void SimplePhraseTable:: ibm1_scoring(LexDic& ibm1){ for(auto& omap: *this){ vector<string> src; split(src,omap.first,is_any_of(" \t")); for(auto& item : omap.second){ vector<string> tgt; split(tgt,item.first,is_any_of(" \t")); item.second.prob=ScoreLex(src, tgt, ibm1); } } }
/** * Return the mass of the given atomic composition. */ double MaxQuantModReader::parseComposition(string composition) { double deltaMass = 0.0; vector<string> components; boost::algorithm::split(components, composition, is_any_of("\t "), boost::token_compress_on); for (vector<string>::iterator i = components.begin(); i != components.end(); i++) { boost::trim(*i); if (i->empty()) { continue; } string element; int quantity; size_t openQuantity = i->find('('); if (openQuantity != string::npos) { element = i->substr(0, openQuantity); size_t closeQuantity = i->find(')', ++openQuantity); if (closeQuantity == string::npos) { // open parenthesis without closing Verbosity::warn("Invalid composition '%s': '(' without ')'", composition.c_str()); return 0.0; } string quantityStr = i->substr(openQuantity, closeQuantity - openQuantity); try { quantity = boost::lexical_cast<int>(quantityStr); } catch (boost::bad_lexical_cast&) { // invalid quantity Verbosity::warn("Invalid quantity for '%s': '%s'", composition.c_str(), quantityStr.c_str()); return 0.0; } } else { element = *i; quantity = 1; } map<string, double>::const_iterator j = elementMasses_.find(element); if (j == elementMasses_.end()) { // element unknown Verbosity::warn("Unknown element for '%s': '%s'", composition.c_str(), element.c_str()); return 0.0; } deltaMass += quantity * j->second; } return deltaMass; }
void MemoryBufferForQuery::LoadLexicon(istream& ifs){ string line; vector<string> vct; vct.reserve(2); P_INFO("Loading Lexicon..."); int nline = 0; while(ifs){ line = ""; getline(ifs, line); split(vct,line,is_any_of(" "),token_compress_on); if(vct.size()<2){ continue; } size_t lineno = lexical_cast<int>(vct[0]); if(lineno < (size_t) nline + 1){ P_FATAL("Mismatch (duplicate) line number, line (%d) \"%s\"",nline+1, line.c_str()); }else if(lineno > nline + 1){ P_ERROR("Mismatch (extra) line number, line (%d) \"%s\"",nline+1, line.c_str()); while(lexicon.size() < lineno-1){ lexicon.push_back(string()); } } lexicon.push_back(vct[1]); dict.insert(DictType::value_type(vct[1],lineno)); nline = lineno; } P_INFO("Loaded %d entries in lexicon", nline); }
string TSasl::getUsername() { const char* username; int result = sasl_getprop(conn, SASL_USERNAME, reinterpret_cast<const void **>(&username)); if (result != SASL_OK) { stringstream ss; ss << "Error getting SASL_USERNAME property: " << sasl_errstring(result, NULL, NULL); throw SaslException(ss.str().c_str()); } // Copy the username and return it to the caller. There is no cleanup/delete call for // calls to sasl_getprops, the sasl layer handles the cleanup internally. string ret(username); // Temporary fix to auth_to_local-style lowercase mapping from // USER_NAME/[email protected] -> user_name/[email protected] // // TODO: The right fix is probably to use UserGroupInformation in the frontend which // will use auth_to_local rules to do this. if (FLAGS_force_lowercase_usernames) { vector<string> components; split(components, ret, is_any_of("@")); if (components.size() > 0 ) { to_lower(components[0]); ret = join(components, "@"); } } return ret; }
void Application_ClientConfigManager::loadApplicationsList() { wstring line; int inserted = 0; wchar_t szFullPath[4096]; GetFullPathName(L"Applications.conf", 4096, szFullPath, NULL); wifstream configF (szFullPath); if (!configF.is_open()) { printf("Application_ConfigManager: Could not open the application config file: Applications.conf\n"); supportedApplications = new wchar_t*[1]; supportedApplications[0] = NULL; return; } while (!configF.eof()) { getline (configF,line); if((line.size() > 0) && (line.at(0) != '#')) { vector<std::wstring> splitLine; for(sf_it it=make_split_iterator(line, token_finder(is_any_of(L"\t"))); it!=sf_it(); ++it) { splitLine.push_back(copy_range<std::wstring>(*it)); } if(splitLine.size() >= 2) { bool downloadURL = false; if(splitLine.size() == 3) { if(splitLine[2] == L"yes") downloadURL = true; } if(applicationsMap.find(splitLine[0]) == applicationsMap.end()) { APPLICATION* a = new APPLICATION(); a->name = splitLine[0]; a->path = splitLine[1]; a->downloadURL = downloadURL; applicationsMap.insert(ApplicationPair(splitLine[0], a)); inserted++; } } } } supportedApplications = new wchar_t*[inserted+1]; int i = 0; stdext::hash_map<wstring, PAPPLICATION>::iterator vit; for(vit = applicationsMap.begin(); vit != applicationsMap.end(); vit++) { supportedApplications[i] = new wchar_t[vit->first.length()+1]; wcscpy_s(supportedApplications[i],vit->first.length()+1, vit->first.c_str()); i++; } supportedApplications[i] = NULL; configF.close(); }
void Strings::split(vector<string>& out, const string& delim, const string& source) { out.clear(); if (source.find(delim) != string::npos) boost::split(out, source, is_any_of(delim), token_compress_on); else out.push_back(source); }
void castSNP::construct(string &chrNum, string &population) { ifstream infile; string prefix = "/home/yulingl/ase_diseases/SNPonChips/allSNPonChip/SNPOnChipInChr"; string fileName = prefix + chrNum; infile.open(fileName.c_str()); string currentLine; vector<string> info; while (!getline(infile, currentLine).eof()) { split(info, currentLine, is_any_of("\t")); string key = chrNum + "_" + info[1]; onChip.insert(key); } infile.close(); fileName = "/home/yulingl/ase_diseases/hapmap_ld/" + population + "_SNPSet/" + chrNum; infile.open(fileName.c_str()); while (!getline(infile, currentLine).eof()) { string key = chrNum + "_" + currentLine; onHapMap.insert(key); } infile.close(); }
bool RHOBJLoader::parseLine(string line){ vector<string> line_split; if(line != ""){ split(line_split, line, is_any_of(" ")); if (line_split[0] == "#"){ //do nothing } else if (line_split[0] == "v") { int num_coords = line_split.size(); for(size_t i = 1; i < (line_split.size()); i++){ if(line_split[i] == "") return true; mesh.vertexes.push_back(boost::lexical_cast<float>(line_split[i])); } } else if (line_split[0] == "vt") { int num_coords = line_split.size(); for(size_t j = 1; j < (line_split.size()); j++){ if(line_split[j] == "") return true; mesh.texcoords.push_back(boost::lexical_cast<float>(line_split[j])); } } else if (line_split[0] == "vn") { int num_coords = line_split.size(); for(size_t k = 1; k < (line_split.size()); k++){ if(line_split[k] == "") return true; mesh.normals.push_back(boost::lexical_cast<float>(line_split[k])); } } else if (line_split[0] == "f") { cerr << "Faces not yet implemented\n"; } else { cerr << "Unknown line pre-fix: " << line_split[0] << endl; return false; } } return true; }
string ExtractURIEndPathSegment(string URI) { if(URI.empty()) return ""; if(Last<char>(URI) == '/') URI.pop_back(); vector<string> splitted; split(splitted, URI, is_any_of("/")); return Last<string>(splitted); }
void processFile(string &chrNum, string &population) { string command; command = "gunzip -c /home/yulingl/ase_diseases/hapmap_ld/ld_chr" + chrNum + "_" + population + ".txt.gz > /home/yulingl/ase_diseases/hapmap_ld/tempFile"; system(command.c_str()); command = "mkdir -p /home/yulingl/ase_diseases/hapmap_ld/" + population + "_1"; system(command.c_str()); command = "mkdir -p /home/yulingl/ase_diseases/hapmap_ld/" + population + "_0.1"; system(command.c_str()); command = "mkdir -p /home/yulingl/ase_diseases/hapmap_ld/" + population + "_SNPSet"; system(command.c_str()); set<string> SNPonHapMap; ifstream infile; ofstream outfileSet, outfileLD1, outfileLD01; string fileName = "/home/yulingl/ase_diseases/hapmap_ld/" + population + "_1/" + chrNum; outfileLD1.open(fileName.c_str()); fileName = "/home/yulingl/ase_diseases/hapmap_ld/" + population + "_0.1/" + chrNum; outfileLD01.open(fileName.c_str()); fileName = "/home/yulingl/ase_diseases/hapmap_ld/" + population + "_SNPSet/" + chrNum; outfileSet.open(fileName.c_str()); infile.open("/home/yulingl/ase_diseases/hapmap_ld/tempFile"); vector<string> info; string currentLine; double r2; while (!getline(infile, currentLine).eof()) { split(info, currentLine, is_any_of(" ")); SNPonHapMap.insert(info[3]); SNPonHapMap.insert(info[4]); r2 = atof(info[6].c_str()); if (r2 >= 0.1) { outfileLD01 << info[3] << "\t" << info[4] << endl; if (r2 >= 1) { outfileLD1 << info[3] << "\t" << info[4] << endl; } } } for (set<string>::iterator it = SNPonHapMap.begin(); it != SNPonHapMap.end(); it ++) { outfileSet << *it << endl; } infile.close(); outfileSet.close(); outfileLD01.close(); outfileLD1.close(); system("rm -f /home/yulingl/ase_diseases/hapmap_ld/tempFile"); }
void TokenOCR<height, width>::parseline(const string& line) { vector<string> parts; split(parts, line, is_any_of("\t")); tag = parts[1]; fold = int(parts[5][0]); for(size_t i = 0; i < height; i++) { for(size_t j = 0; j < width; j++) { img[i][j] = int(parts[6 + i * width + j][0]-'0'); } } }
/// /// Parse line containing SDP fmtp attribute for H.264. /// /// @post config is non-empty if returns true, empty if false. /// /// @param[in] line Line containing the fmtp attribute. /// @param[out] config Configuration bytes. /// @return Whether the fmtp attribute was parsed. bool RTSPUDPH264:: ParseFmtp(const string &line, vector<BYTE> &config) const { bool parsed = false; config.clear(); // Make sure we have an fmtp line to parse. if (!line.empty()) { vector<string> fmtp_parts; string trimmed = trim_copy_if(line, is_any_of(" ;")); split(fmtp_parts, trimmed, is_any_of(" ;"), token_compress_on); string modeString; string sets; BOOST_FOREACH(const string ¶meter, fmtp_parts) { if (starts_with(parameter, "packetization-mode")) { string::size_type iIndex = parameter.find("="); if (iIndex != string::npos) { iIndex++; // move past '=' modeString = ¶meter[iIndex]; } } else if (starts_with(parameter, "sprop-parameter-sets")) { string::size_type iIndex = parameter.find("="); if (iIndex != string::npos) { iIndex++; // move past '=' sets = ¶meter[iIndex]; } } } parsed = SupportedPacketizationMode(modeString) && ParseSpropParameterSets(sets, config); }
Script ScriptParser::Parse( std::wstring const& script ) const { std::size_t index = 0; Script result(this); std::vector<std::wstring> scriptLines; split(scriptLines, script, is_any_of(L"\r\n"), token_compress_on); scriptLines.erase(std::remove_if(scriptLines.begin(), scriptLines.end(), [](std::wstring const& a) -> bool { return std::find_if(a.begin(), a.end(), std::not1(std::ptr_fun(iswspace))) == a.end(); }), scriptLines.end()); std::vector<std::wstring>::iterator begin, end; begin = scriptLines.begin(); end = scriptLines.end(); while (begin != end) { if (!starts_with(*begin, L":")) { ++begin; continue; } std::wstring::iterator sectionStart = begin->begin(); if (sectionStart != begin->end()) { ++sectionStart; } std::wstring::iterator argumentStart = std::find_if(sectionStart, begin->end(), iswspace); std::wstring scriptTarget(sectionStart, argumentStart); to_lower(scriptTarget); auto sectionIterator = sectionTypes.find(scriptTarget); if (sectionIterator == sectionTypes.end()) { throw UnknownScriptSectionException(scriptTarget); } ISectionDefinition const *def = sectionIterator->second.get(); if (argumentStart != begin->end()) { ++argumentStart; } std::wstring argument(argumentStart, begin->end()); ++begin; std::vector<std::wstring>::iterator endOfOptions = begin; endOfOptions = std::find_if(begin, end, [](std::wstring const& a) { return starts_with(a, L":"); }); result.Add(def, argument, std::vector<std::wstring>(begin, endOfOptions), index++); } return result; }
void Model::preparePVector(){ string temp; list<string> tokenList; vector<SubComponent *> subComponents = device->getSubComponents(); SubComponent* sc; int i=0; pwr_consumers_cnt = 0; //Storing the device subcomponents order in a map, i.e., powerMappingDeviceOrder in order to access them while filling the P vector for(vector<SubComponent *>::iterator it1 = subComponents.begin(); it1 != subComponents.end(); it1++){ sc=(*it1); //avoid using (i,j) concatenated with the names in the high-res components if (sc->isPrimary()){ powerMappingDeviceOrder.insert(pair<string, int> (sc->getComponent()->getName(), i)); }else{ powerMappingDeviceOrder.insert(pair<string, int> (sc->getName(), i)); } if (sc->getComponent()->isPowerGen() && (sc->getComponent()->hasFloorPlan() || sc->isPrimary())){ pwr_consumers_cnt++; } i++; } //Opening the power trace file for reading string powerTraceFileAddr = device->getPowerTraceFile(); powerTraceFile.open(powerTraceFileAddr.c_str(), ifstream::in); if (!powerTraceFile.is_open()){ cerr<<"Could not open "<<powerTraceFileAddr<<" for parsing as the power trace."<<endl; exit(-1); } do{ getline(powerTraceFile, temp); algorithm::trim(temp); }while (isComment(temp) && powerTraceFile.eof()==false); if (powerTraceFile.eof()){ cerr<<"The file does not contain valid power trace."<<endl; exit (-1); } split(tokenList, temp, is_any_of("\t "), token_compress_on); i=0; BOOST_FOREACH(string token, tokenList){ powerMappingTraceOrder.insert(pair<int, string> (i, token)); i++; }
void TcpBase::syncComm() { std::string message; while (this->getNextMessage(&message)) { size_t separator = message.find(' '); if (separator == std::string::npos) { this->handleAction(message, std::vector<std::string>()); } else { std::string action = message.substr(0, separator); std::string parametersStr = message.substr(separator + 1); std::vector<std::string> parameters; split(parameters, parametersStr, is_any_of(" ")); this->handleAction(action, parameters); } } }
TTClient::TTClient(string serverList){ tcrdbPtr_ = tcrdbnew(); vector<string> servers; split(servers, serverList, is_any_of(","), token_compress_on); for(size_t i = 0; i < servers.size(); i++){ string server = servers[i]; size_t p = server.find(":"); if(p != string::npos){ string ip = server.substr(0, p); string portStr = server.substr(p+1); short port = boost::lexical_cast<short>(portStr); serverList_.push_back(make_pair(ip, port)); } } LOG_INFO("TTClient::TTClient => Created : serverList = " << serverList); }
void user_node_description(std::vector<string>& user_stas, std::vector<Node> all_node, std::vector<int> user_tree){ string temp; bool found=false; user_stas.clear(); for (std::vector<int>::iterator i = user_tree.begin(); i != user_tree.end(); ++i) { // stas+= find_node_based_on_real_id(all_node, (*i) ).get_description(); temp=find_node_based_on_real_id(all_node, (*i) ).get_description(); // cout<<temp; std::vector<std::string> tokens; boost::split( tokens, temp, is_any_of( "\n" ) ); // print( tokens ); for (std::vector<string>::iterator i2 = tokens.begin(); i2 != tokens.end(); ++i2) { // cout<< (*i2)<<" "; for (std::vector<string>::iterator i3 = user_stas.begin(); i3 != user_stas.end(); ++i3) { if( get_word_only(*i2).compare(get_word_only(*i3)) ==0 ){ found=true; (*i3)= combine_2_description( *i3, get_number_only(*i2) ); // cout<<combine_2_description( *i3, get_number_only(*i2) ); // cout<< get_number_only(*i2); break; } } if(found==false){ user_stas.push_back(*i2); } found=false; } } // std::string expression = "+10 to Intelligence"; // std::string number; // boost::regex re("\\d+"); // boost::sregex_iterator i(expression.begin (),expression.end (),re); // boost::sregex_iterator j; // for(; i!=j; ++i) { // number+= i->str(); // } // int a=atoi(number.c_str())+10; // string s; // std::size_t found = expression.find(number); // expression.replace(found,number.size(),to_string(a)); // cout<<stas; }
void castHeterozygousSNP::construct(string &subject, string &chrNum) { ifstream infile; string fileName = HETEROZYGOUSSNPSLOCATION + subject + "/" + chrNum; infile.open(fileName.c_str()); string currentLine; vector<string> info; while (!getline(infile, currentLine).eof()) { if (currentLine[0] != '#') { string SNPID; split(info, currentLine, is_any_of("\t")); SNPID = info[0].substr(3) + "_" + info[2]; SNPs.insert(SNPID); } } };
void castTSS::construct(string &chrNum) { ifstream infile; string prefix = "/home/yulingl/ase_diseases/geneStart/geneStartinChr"; string fileName; fileName = prefix + chrNum; infile.open(fileName.c_str()); vector<string> info; string currentLine; while (!getline(infile, currentLine).eof()) { split(info, currentLine, is_any_of("\t")); unsigned long pos; pos = strtoul(info[2].c_str(), NULL, 0); TSS.push_back(pos); } sort(TSS.begin(), TSS.end()); infile.close(); }
void castLD::constructOverChr(string &chrNum, string &population) { ifstream infile; string fileName = "/home/yulingl/ase_diseases/hapmap_ld/" + population + "_0.1/" + chrNum; infile.open(fileName.c_str()); vector<string> info; string currentLine; while (!getline(infile, currentLine).eof()) { split(info, currentLine, is_any_of("\t")); string key1 = chrNum + "_" + info[0]; string key2 = chrNum + "_" + info[1]; map<string, set<string> >::iterator pIt1 = tag_SNPinLD.find(key1); map<string, set<string> >::iterator pIt2 = tag_SNPinLD.find(key2); if (pIt1 == tag_SNPinLD.end()) { set<string> tmp; tmp.insert(key1); tmp.insert(key2); tag_SNPinLD[key1] = tmp; } else { tag_SNPinLD[key1].insert(key1); tag_SNPinLD[key1].insert(key2); } if (pIt2 == tag_SNPinLD.end()) { set<string> tmp1; tmp1.insert(key1); tmp1.insert(key2); tag_SNPinLD[key2] = tmp1; } else { tag_SNPinLD[key2].insert(key1); tag_SNPinLD[key2].insert(key2); } } infile.close(); }
void TcpBase::receiveMessages(tcp::socket& s) { mutex::scoped_lock lock(mutex_); boost::system::error_code error; char data[MAX_LEN]; size_t length = s.read_some(asio::buffer(data), error); if (length == 0 && error == asio::error::would_block) { boost::this_thread::sleep(boost::posix_time::milliseconds(1)); return; } if (error) { throw boost::system::system_error(error); } data[length] = '\0'; logTrace(name_ + " TcpServer new message"); std::string messagesStr(data); std::vector<std::string> messages; split(messages, messagesStr, is_any_of("\r\n")); for_each(messages.begin(), messages.end(), [this](std::string& message) { logTrace("RX: " + message); inQueue_.push(message); }); }
bool RedisClient::connect(){ vector<string> addrVec; split(addrVec, addrs_, is_any_of(","), token_compress_on); if(addrVec.size() == 0){ LOG_ERROR("RedisClient::connect => can not found addr from addrs [" << addrs_ << "]"); return false; } for(size_t i = 0; i < addrVec.size(); i++){ string addr = addrVec[i]; size_t p = addr.find(":"); if(p != string::npos){ string ip = addr.substr(0, p); string portStr = addr.substr(p+1); short port = boost::lexical_cast<int>(portStr); redisContext *context = redisConnect(ip.c_str(), port); if(context->err){ LOG_ERROR("RedisClient::connect => connect redis server error : err = " << context->errstr); return false; } LOG_INFO("RedisClient::connect => connect redis server : ip = " << ip << " port = " << port); redisClusters_.push_back(context); } else { LOG_ERROR("RedisClient::connect => addr format error : addr = [" << addr << "]"); return false; } } if(redisClusters_.size() == 0){ LOG_ERROR("RedisClient::connect => connect to redis server failure"); return false; } LOG_INFO("RedisClient::connect => client [" << index_ << "] connect success : cluster size = " << redisClusters_.size()); return true; }
void KeysValues::ReadLine(CS& line) { // separate with sep_kv vector<string> kv; split(kv, line, is_any_of(sep_kv_)); // check the structure if(kv.size() != 2) { string msg; SUB_LOCATION(msg); msg += "line must be 'key:value'"; throw runtime_error(msg); } // copy string key = trim_copy(kv[0]); string val = trim_copy(kv[1]); // string key = kv[0]; // string val = kv[1]; // add key value as string this->Add<string>(key, val); }
vector<string> split(const string& s, const string& tokens) { vector<string> res; split(res, s, is_any_of(tokens), token_compress_on); return res; }