// Maps highest frequency of codons to each amino acid vector<float> CodonFrequency::createMaxMap(multimap<char, pair<int, float> > AAtoCodonMap){ // cout << "------maxFreq------" << endl; vector<float> maxMap; float maxFreq; // Loops through all amino acids // If char rep of AA exists // Calculate highest frequency to maxMap for (char AA = 'A'; AA <= 'Z'; AA++) { int addressAA = AA - 65; if (AA == 'B' || AA == 'J' || AA == 'O' || AA == 'U' || AA == 'X') { maxMap.push_back(-1); // continue; } else if (AAtoCodonMap.count(AA) > 1) { maxFreq = findMax(AAtoCodonMap, AA); maxMap.push_back(maxFreq); // continue; } else if (AAtoCodonMap.count(AA) == 1) { maxMap.push_back(AAtoCodonMap.find(AA)->second.second); } // to print values: comment out the continues in if statements // cout << addressAA << " " << AA << " " << maxMap[addressAA] << endl; } return maxMap; }
int insert_balanced(int id, Vec2 pos){ int quad_id = 0, depth = 0; while(flat_tree.count(quad_id)>=max_items_per_quad){ ++depth; quad_id = get_quad_id(pos,depth); // msgm( // "quad_id",quad_id, // "count()",flat_tree.count(quad_id), // ); } msgm("inserting", id, "at", quad_id, "has", flat_tree.count(quad_id)); insert(id,pos,depth); return quad_id; }
// Maps average frequency of codons to each amino acid vector<float> CodonFrequency::createAvgMap(multimap<char, pair<int, float> > AAtoCodonMap) { // cout << "------avgFreq------" << endl; int addressAA; int codonPerAA; // Numbers of codons that code for an amino acid float sumFreq; // Sum of codon frequencies for an amino acid float avgFreq; // sumFreq/codonPerAA to calculate average frequency for an amino acid vector<float> avgMap; for (char AA = 'A'; AA <= 'Z'; AA++) { addressAA = AA-65; codonPerAA = 0; sumFreq = 0; avgFreq = 0; if (AA == 'B' || AA == 'J' || AA == 'O' || AA == 'U' || AA == 'X') { avgMap.push_back(-1); // continue; } else if (AAtoCodonMap.count(AA) > 1) { pair< multimap<char, pair<int, float> >::iterator, multimap<char, pair<int, float> >::iterator> ret; ret = AAtoCodonMap.equal_range(AA); for (multimap<char, pair<int, float> >::iterator it = ret.first; it != ret.second; ++it) { // cout << AA << " " << it->second.second << endl; sumFreq += it->second.second; codonPerAA++; } avgFreq = sumFreq/codonPerAA; // cout << sumFreq << " / " << codonPerAA << " = " << avgFreq << endl; avgMap.push_back(avgFreq); // continue; } else if (AAtoCodonMap.count(AA) == 1) { avgMap.push_back(AAtoCodonMap.find(AA)->second.second); // continue; } // cout << addressAA << " " << AA << " " << avgMap[addressAA] << endl; } return avgMap; }
void writeMetadataFile( const string coll, boost::filesystem::path outputFile, map<string, BSONObj> options, multimap<string, BSONObj> indexes ) { toolInfoLog() << "\tMetadata for " << coll << " to " << outputFile.string() << std::endl; bool hasOptions = options.count(coll) > 0; bool hasIndexes = indexes.count(coll) > 0; BSONObjBuilder metadata; if (hasOptions) { metadata << "options" << options.find(coll)->second; } if (hasIndexes) { BSONArrayBuilder indexesOutput (metadata.subarrayStart("indexes")); // I'd kill for C++11 auto here... const pair<multimap<string, BSONObj>::iterator, multimap<string, BSONObj>::iterator> range = indexes.equal_range(coll); for (multimap<string, BSONObj>::iterator it=range.first; it!=range.second; ++it) { indexesOutput << it->second; } indexesOutput.done(); } ofstream file (outputFile.string().c_str()); uassert(15933, "Couldn't open file: " + outputFile.string(), file.is_open()); file << metadata.done().jsonString(); }
void writeMetadataFile( const string coll, boost::filesystem::path outputFile, map<string, BSONObj> options, multimap<string, BSONObj> indexes ) { log() << "\tMetadata for " << coll << " to " << outputFile.string() << endl; ofstream file (outputFile.string().c_str()); uassert(15933, "Couldn't open file: " + outputFile.string(), file.is_open()); bool hasOptions = options.count(coll) > 0; bool hasIndexes = indexes.count(coll) > 0; if (hasOptions) { file << "{options : " << options.find(coll)->second.jsonString(); if (hasIndexes) { file << ", "; } } else { file << "{"; } if (hasIndexes) { file << "indexes:["; for (multimap<string, BSONObj>::iterator it=indexes.equal_range(coll).first; it!=indexes.equal_range(coll).second; ++it) { if (it != indexes.equal_range(coll).first) { file << ", "; } file << (*it).second.jsonString(); } file << "]"; } file << "}"; }
//devuelve cuantos elementos de 'mi_multimap' usan 'llave' como llave int contarElementosMultimap(multimap<string,int> mi_multimap,string llave) {//Creo una variable donde guardare los valores de multimap, con la funcion "count" de multimap cuento a ver cuantos valores tiene el multimap y retorno la variable para saber cuantos veces se hayaron los valores int conta=1; //por warning los inicialize if(conta != 0) { conta = mi_multimap.count(llave); } return conta; }
void balance_all(){ // int prev = -1; // unused for(auto&a:has_children){ if(flat_tree.count(a)>=max_items_per_quad) balance(a); } // for(auto1) }
void printmultimap(multimap <string, string> &authors) { typedef multimap <string, string>::size_type sz_type; sz_type co = authors.count("Barth, John"); //cout << count; multimap <string, string>::iterator iter = authors.find("Barth, John"); for (sz_type cnt = 0; cnt != co; ++cnt,++iter) { cout << iter->first << ":--->" << iter->second << endl; } }
void balance(int id){ auto count = flat_tree.count(id);; if (count > max_items_per_quad) { int target_depth = get_depth(id) + logn(count, 4); for (auto&a : query_quad(id)) { //flat_tree.insert({}) insert(id, positions[id], target_depth); } flat_tree.erase(id); // erase all by key, can also erase iterator } }
//devuelve la suma de los elementos de 'mi_multimap' que usan 'llave' como llave int sumaElementosMultimap(multimap<string, int> mi_multimap, string llave) { int cont = 0; // Creo una variable cont while(mi_multimap.count(llave) != 0) //mientras el conteo de las llaves no sea cero { int c = mi_multimap.find(llave)-> second; //La variable c toma el valor del segundo elemento de la llave cont = cont + c; //Suma los valores mi_multimap.erase(mi_multimap.find(llave)); //se borra el ultimo elemento } return cont; //devuelve la suma }
// Prints each codon that codes for the amino acid void CodonFrequency::printMap(multimap<char, pair<int, float> > AAtoCodonMap) { for (char AA = 'A'; AA <= 'Z'; AA++) { pair< multimap<char, pair<int, float> >::iterator, multimap<char, pair<int, float> >::iterator> ret; if (AAtoCodonMap.count(AA) <= 0) continue; ret = AAtoCodonMap.equal_range(AA); cout << AA << " =>"; for (multimap<char, pair<int, float> >::iterator it = ret.first; it!=ret.second; ++it) { cout << ' ' << it->second.first; } cout << endl; } }
int main() { init(); rdio(namenum); lli n; cin >> n; if (M.count(n) > 0) { for (auto it = M.equal_range(n).first; it != M.equal_range(n).second; ++it) { cout << it->second << endl; } } else cout << "NONE" << endl; return 0; }
void preprocess() { for (int i = 0; i < raw_heads.size(); i++) { raw_head_to_body.insert(pair<int,int>(toInt((Lit) raw_heads[i]), i)); } for (int i = 0; i < raw_heads.size(); i++) { if (raw_posb[i].size() == 1 && raw_negb[i].size() == 0) { if (raw_head_to_body.count(toInt((Lit) raw_posb[i][0])) == 1) { int r = raw_head_to_body.find(toInt((Lit) raw_posb[i][0]))->second; raw_bl[i] = raw_posb[i][0]; raw_posb[r].copyTo(raw_posb[i]); raw_negb[r].copyTo(raw_negb[i]); raw_heads[r] = bv_false; } } } for (int i = 0; i < raw_heads.size(); i++) { if (raw_heads[i] == bv_false) continue; getId(raw_heads[i]); } }
//devuelve cuantos elementos de 'mi_multimap' usan 'llave' como llave int contarElementosMultimap(multimap<string,int> mi_multimap,string llave) { return mi_multimap.count(llave); //count cuenta los valores del multimap }
void InputHandler::initParamsFromDOM(DOMNode *node, multimap<string, ParamWrapper*> registry) { assert(node); char *tmp = XMLString::transcode(node->getNodeName()); crusde_debug("%s, line: %d, initParamsFromDOM for node: %s.", __FILE__, __LINE__, tmp); XMLString::release(&tmp); DOMNode *child = node->getFirstChild(); DOMNamedNodeMap *attributes = NULL; DOMNode *attr = NULL; multimap<string, ParamWrapper*>::iterator key_iter; pair< multimap<string, ParamWrapper*>::iterator, multimap<string, ParamWrapper*>::iterator > key_range; list<string> params_set; int count_keys(-1); unsigned int count_set(0); int empty_param(0); while (child) { if( child->getNodeType() == DOMNode::ELEMENT_NODE) { attributes = child->getAttributes(); attr = attributes->getNamedItem(ATTR_name.xmlStr()); char* name = XMLString::transcode(attr->getNodeValue()); if( XMLString::compareIString(child->getNodeName(), TAG_parameter.xmlStr()) == 0 ) { //get number of keys that equal name count_keys = static_cast<int>( registry.count(string(name)) ); //if there is anything in the registry ... if( count_keys > 0 ) { //equal_range gives two results: an iterator to the first and last element with key==name key_range = registry.equal_range(string(name)); //all keys have values that are adresses of double variables in the repsective plugins //each of those variables now gets a value assigned. the same value. for ( key_iter=key_range.first; key_iter != key_range.second; ++key_iter) { //get the value from the DOM StrXML value(attributes->getNamedItem(ATTR_value.xmlStr())->getNodeValue()); //write it into the variable that's strored at key_iter->second if( (key_iter->second)->isString() ) { (key_iter->second)->setValue( value.cppStr() ); } else if( (key_iter->second)->isDouble() ) { (key_iter->second)->setValue( static_cast<double>( atof(value.cStr()) ) ); } ++count_set; } //memorize the key that was set only once params_set.push_back(key_range.first->first); } else //if not found there might be a spelling mistake either in input, or plugin, or both :) { StrXML paramName(attributes->getNamedItem(ATTR_name.xmlStr())->getNodeValue()); crusde_warning("Parameter %s (coming from the experiment definition) not registered! Misspelled in XML file or Plug-in definition?",paramName.cStr()); } } XMLString::release(&name); } child = child->getNextSibling(); } //two cases are possible for leftover parameters: // i) they are optional parameters - check registry for that // ii) they are unitialized - oh well, we gotta stop there if(count_set < registry.size()) { multimap<string, ParamWrapper*>::iterator map_iter = registry.begin(); list<string>::iterator found_iter; string out_string("Error: Parameters that remain uninitialized: \n"); while (map_iter != registry.end()) { if(!map_iter->second->isOptional()) { found_iter = params_set.begin(); //as long as we're not at the end and could not find the parameter in the list of set //parameters, continue looking. while( found_iter != params_set.end() && (*found_iter).compare(map_iter->first) != 0 ) { ++found_iter; } //if we're at the end, the parameter was not in out list ... tell the user. if(found_iter==params_set.end() ) { ++empty_param; out_string.append("\t"); out_string.append(map_iter->first); out_string.append("\n"); } } //get to the next unique value in the registry ... avoid printing multiple keys twice. map_iter = ( registry.equal_range(map_iter->first) ).second; } if(empty_param > 0) { crusde_error("%s, Aborting.", out_string.c_str()); } } }